forked from 0xFableOrg/roll-op
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devenv.sh
executable file
·73 lines (63 loc) · 2.33 KB
/
devenv.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
#!/usr/bin/env bash
# Description: This script is used to setup the development environment for the project.
check_python_version() {
# Check python version if greater or equal than 3.10, otherwise exit
python_version=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
if python3 -c "import sys; sys.exit(not (sys.version_info >= (3, 10)))"; then
echo "Python version is $python_version"
return 0
else
echo "Python version is $python_version, but 3.10 or greater is required"
return 1
fi
}
activate_venv() {
# Check if venv directory exists, otherwise create it. Then activate venv
if [ -d "venv" ]; then
echo "venv directory exists"
else
echo "venv directory does not exist, creating it now"
python3 -m venv venv
fi
echo "activating venv"
source ./venv/bin/activate
}
install_dev_dependencies() {
# Check if pip3 version is greater or equal than 21.2.1, otherwise upgrade it
pip3_version=$(python3 -c "import pip; print(pip.__version__)")
check_pip3_version() {
python3 -c \
"import pip;\
import sys;\
sys.exit(not [int(x) for x in pip.__version__.split('.')] >= [21, 2, 1])"
}
if check_pip3_version; then
echo "pip3 version is $pip3_version"
else
echo "pip3 version is $pip3_version, but 21.2.1 or greater is required"
pip3 install --upgrade pip
fi
# Check if ruff 0.3.2 is installed, otherwise install this version
ruff_version=$(pip3 freeze | grep ruff | awk -F'==' '{print $2}')
if [ "$ruff_version" = "0.3.2" ]; then
echo "ruff version is $ruff_version"
else
echo "ruff version is $ruff_version, but 0.3.2 is required"
pip3 install ruff==0.3.2
fi
# Check if autopep8 is installed, otherwise install it
autopep8_version=2.0.4
if ! command -v autopep8 &> /dev/null; then
echo "autopep8 could not be found, installing it now"
pip3 install autopep8==$autopep8_version
elif [ "$(autopep8 --version | awk '{print $2}')" != $autopep8_version ]; then
echo "forcing autopep8 to right version"
pip3 install autopep8==$autopep8_version
else
echo "autopep8 version $autopep8_version"
fi
}
if check_python_version; then
activate_venv
install_dev_dependencies
fi