-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
executable file
·91 lines (77 loc) · 2.65 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# Exit on error. Append "|| true" if you expect an error.
set -o errexit
# Exit on error inside any functions or subshells.
set -o errtrace
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
set -o nounset
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump | gzip`
set -o pipefail
PYTHON_VERSION=3.10.2
if [ "$(uname)" == "Darwin" ]; then
SYSTEM="Darwin"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
SYSTEM="Linux"
else
echo "Unsupported OS. Only Linux and MacOS are supported."
exit 1
fi
if [ ${SYSTEM} == "Darwin" ]; then
if ! [ $(command -v brew) ]; then
echo "Homebrew not found. Please follow the instructions at brew.sh to install Homebrew."
fi
fi
function setup_pyenv() {
if ! [ $(command -v pyenv) ]; then
if [ ${SYSTEM} == "Darwin" ]; then
echo "Installing pyenv"
brew install --upgrade pyenv
echo "eval \"\$(pyenv init -)\"" >> ${HOME}/.profile
elif [ ${SYSTEM} == "Linux" ]; then
echo "Pyenv not found. Please follow the instructions at https://github.com/pyenv/pyenv#installation."
exit 1
fi
fi
eval "$(pyenv init -)"
}
function setup_python() {
if ! [ $(command -v python) ]; then
echo "Python not found, installing now."
echo "You need either curl or wget, gcc, libffi-dev, libssl-dev, libz-dev and make on your machine, otherwise the installation will fail."
pyenv install --skip-existing ${PYTHON_VERSION}
pyenv global ${PYTHON_VERSION}
else
CURRENT_PYTHON_VERSION="$(python -c 'import platform; print(platform.python_version())' || true)"
if [ ${CURRENT_PYTHON_VERSION} != ${PYTHON_VERSION} ]; then
echo "Python ${PYTHON_VERSION} missing. Installing now."
pyenv install --skip-existing ${PYTHON_VERSION}
pyenv global ${PYTHON_VERSION}
fi
fi
}
function setup_pip() {
PIP_VERSION="$(python -m pip --version || true)"
if [ -z "${PIP_VERSION}" ]; then
echo "Pip not found. Please follow the instructions at https://pip.pypa.io/en/stable/installing."
exit 1
fi
}
function setup_poetry() {
if ! [ $(command -v poetry) ]; then
echo "Installing poetry."
curl -sSL https://install.python-poetry.org | python -
fi
}
setup_pyenv
setup_python
setup_pip
setup_poetry
cat <<EOF
Your Python environment is now ready. Please run:
>>> poetry install
To setup the virtual environment on your machine.
To activate the virtual environment you can use:
>>> poetry shell
Or you can prefix each command with:
>>> poetry run <command>
EOF