-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·86 lines (75 loc) · 1.81 KB
/
setup.sh
File metadata and controls
executable file
·86 lines (75 loc) · 1.81 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
<<DESCRIPTION
This script automates the setup of a Python virtual environment.
It creates a virtual environment and then installs all required
dependencies from a requirements.txt file.
DESCRIPTION
GREEN='\033[32m'
YELLOW='\033[33m'
RESET='\033[0m'
RED='\033[31m'
spinner() {
local pid=$1
local message=$2
local delay=0.1
local spinstr='|/-\'
printf "${YELLOW}$message${RESET}"
tput civis
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf "${GREEN}%c${RESET}" "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b"
done
printf "\b"
tput cnorm
}
check_error() {
if [ $1 -ne 0 ]; then
printf " ${RED}✗${RESET}\n"
cat .install_cache
printf "\n"
rm .install_cache
exit $1
else
printf " ${GREEN}✓${RESET}\n"
fi
}
create_venv() {
(test -d venv) || python -m venv venv 1>/dev/null 2>.install_cache &
pid=$!
spinner $pid "Setting up venv... "
wait $pid
check_error $?
}
install_dependencies() {
venv/bin/pip install -U pip 1>/dev/null 2>.install_cache && venv/bin/pip install -r requirements.txt 1>/dev/null 2>.install_cache &
pid=$!
spinner $pid "Installing dependencies... "
wait $pid
check_error $?
[ -f .install_cache ] && rm .install_cache
}
clean_venv() {
if [ -d "venv" ]; then
rm -rf venv &
pid=$!
spinner $pid "Removing venv... "
wait $pid
check_error $?
else
printf "${YELLOW}No virtual environment found to clean ${GREEN}✓${RESET}\n"
fi
}
case "$1" in
install)
create_venv
install_dependencies
;;
clean)
clean_venv
;;
*)
echo "Usage: $0 {install|clean}"
exit 1
esac