-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
executable file
·101 lines (78 loc) · 1.22 KB
/
main.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
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# Colors
YELLOW='\e[33m'
NC='\e[0m' # No Color
# Constants
WARN="${YELLOW}WARN: ${NC}"
# Directories
BIN_DIR=./env/bin
PARAMS=""
source_func() {
source "$BIN_DIR/activate"
}
env() {
python3 -m venv env
}
check_env() {
if [ ! -f "$BIN_DIR/activate" ]; then
echo -e "${WARN}Creating environment"
env
fi
}
check_source() {
check_env
if [[ -z "${VIRTUAL_ENV}" ]]; then
echo -e "${WARN}Source environment"
source_func
fi
}
check_install() {
check_source
if [ ! -f "$BIN_DIR/pytest" ]; then
echo -e "${WARN}Installation not detected (using pytest as source of truth)"
install
fi
}
install() {
check_source
pip3 install -r requirements.txt
}
test_project() {
check_source
pytest $PARAMS
}
lint() {
check_install
python3 -m flake8 --exclude=parsetab.py ./app --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
}
run() {
check_install
python3 -m app $PARAMS
}
for i in ${@:2}
do
PARAMS="$PARAMS $i"
done
case $1 in
run)
run
;;
test)
test_project
;;
install)
install
;;
env)
env
;;
activate)
source_func
;;
lint)
lint
;;
*)
echo -e "${WARN}unknown command\n"
;;
esac