-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvenv_setup.sh
More file actions
executable file
·96 lines (80 loc) · 1.45 KB
/
venv_setup.sh
File metadata and controls
executable file
·96 lines (80 loc) · 1.45 KB
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
92
93
94
95
96
#!/bin/sh
#
# Setup virtual environment.
# Variables
VENV=".venv"
REQ="requirements.txt"
main () {
version_check
venv_create
venv_activate
}
# Check python3 and pip3
version_check() {
if ! check_cmd python3; then
warn "Please install python3"
exit 1
fi
if ! check_cmd pip3; then
warn "Please install pip3"
exit 1
fi
}
# Create virtual environment
venv_create() {
if ! check_exist "${VENV}"; then
python3 -m venv ${VENV}
ok "Virtual environment created"
else
info "Virtual environment existed"
fi
}
# Activate virtual environment
venv_activate() {
if check_exist "${VENV}"; then
source ${VENV}/bin/activate
ok "Virtual environment activated"
else
err "Unable to find virtual environment"
fi
pip install --upgrade pip
# Install packages by requirements file
if check_exist "${REQ}"; then
pip install -r ${REQ}
ok "Packages installed"
fi
}
#
# Utils
#
# Colors
CLEAR='\033[2K'
NC='\033[0m'
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[0;37m'
info() {
printf "\r${CLEAR} [ ${BLUE}..${NC} ] $1\n"
}
ok() {
printf "\r${CLEAR} [ ${GREEN}OK${NC} ] $1\n"
}
warn() {
printf "\r${CLEAR} [ ${YELLOW}!!${NC} ] $1\n"
}
err() {
printf "\r${CLEAR} [ ${RED}ERR${NC} ] $1\n"
exit
}
check_cmd() {
command -v "$1" >/dev/null 2>&1
}
check_exist() {
test -e "$1" >/dev/null 2>&1
}
main "$@"