generated from Randers-Kommune-Digitalisering/python-app-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-dev-linux.sh
executable file
·86 lines (70 loc) · 2.11 KB
/
setup-dev-linux.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
#!/bin/bash
# To run:
# . ./setup-dev-linux.sh
# OR
# source ./setup-dev-linux.sh
check_python() {
if ! command -v python &> /dev/null; then
echo "python is not installed. Installing..."
apt-get update
apt-get -y install python3.10
alias python='/usr/bin/python3.10'
echo "python installation complete."
else
local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[0:2])))')
major="${python_version%%.*}"
minor="${python_version#*.}"
if [ "$major" -lt 3 ] || [ "$minor" -lt 10 ]; then
echo "python version is '$python_version'. Installing version 3.10..."
apt-get update
apt-get -y install python3.10
alias python='/usr/bin/python3.10'
echo "python installation complete."
fi
fi
}
check_virtualenv() {
if ! command -v virtualenv &> /dev/null; then
echo "virtualenv is not installed. Installing..."
python -m pip install --user virtualenv
echo "virtualenv installation complete."
fi
}
create_venv() {
local env_name=${1:-".venv"}
if [ -d "$env_name" ]; then
echo "Virtual environment '$env_name' already exists. Aborting."
return 1
fi
python -m venv "$env_name"
source "./$env_name/bin/activate"
pip install -U pip
}
activate_venv() {
local env_name=${1:-".venv"}
if [ ! -d "$env_name" ]; then
echo "Virtual environment '$env_name' not found. Use '$0 create [env_name]' to create one."
return 1
fi
source "./$env_name/bin/activate"
}
install_deps() {
local env_name=${1:-".venv"}
if [ ! -d "$env_name" ]; then
echo "Virtual environment '$env_name' not found. Use '$0 create [env_name]' to create one."
return 1
fi
source "./$env_name/bin/activate"
if [ -f "src/requirements.txt" ]; then
pip install -Ir src/requirements.txt
fi
if [ -f "requirements-dev.txt" ]; then
pip install -Ir requirements-dev.txt
fi
}
check_python
check_python
check_virtualenv
create_venv
activate_venv
install_deps