-
Notifications
You must be signed in to change notification settings - Fork 15
/
run_check.sh
executable file
·79 lines (71 loc) · 2.27 KB
/
run_check.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
#!/bin/bash
#
# Shell script for formating, linting and unit test
#
# - Author: Jongkuk Lim
# - Contact: [email protected]
# Bash 3 does not support hash dictionary.
# hput and hget are alternative workaround.
# Usage)
# hput $VAR_NAME $KEY $VALUE
hput() {
eval "$1""$2"='$3'
}
# Usage)
# `hget $VAR_NAME $KEY`
hget() {
eval echo '${'"$1$2"'#hash}'
}
# Define command names
CMD_NAME=(
"format"
"lint"
"test"
"doc"
"doc_server"
"init_conda"
"init_precommit"
"init"
"all"
)
# Define descriptions
hput CMD_DESC format "Run formating"
hput CMD_DESC lint "Run linting check"
hput CMD_DESC test "Run unit test"
hput CMD_DESC doc "Generate MKDocs document"
hput CMD_DESC doc_server "Run MKDocs hosting server (in local)"
hput CMD_DESC init_conda "Create conda environment with default name"
hput CMD_DESC init_precommit "Install pre-commit plugin"
hput CMD_DESC init "Run init-conda and init-precommit"
hput CMD_DESC all "Run formating, linting and unit test"
# Define commands
hput CMD_LIST format "black . && isort . && docformatter -i -r . --wrap-summaries 88 --wrap-descriptions 88"
hput CMD_LIST lint "env PYTHONPATH=. pytest --pylint --mypy --flake8 --ignore tests --ignore cpp"
hput CMD_LIST test "env PYTHONPATH=. pytest tests --cov=scripts --cov-report term-missing --cov-report html"
hput CMD_LIST doc "env PYTHONPATH=. mkdocs build --no-directory-urls"
hput CMD_LIST doc_server "env PYTHONPATH=. mkdocs serve -a 127.0.0.1:8000 --no-livereload"
hput CMD_LIST init_conda "conda env create -f environment.yml"
hput CMD_LIST init_precommit "pre-commit install --hook-type pre-commit --hook-type pre-push"
hput CMD_LIST init "`hget CMD_LIST init_conda` && `hget CMD_LIST init_precommit`"
hput CMD_LIST all "`hget CMD_LIST format` && `hget CMD_LIST lint` && `hget CMD_LIST test`"
for _arg in $@
do
if [[ `hget CMD_LIST $_arg` == "" ]]; then
echo "$_arg is not valid option!"
echo "--------------- $0 Usage ---------------"
for _key in ${CMD_NAME[@]}
do
echo "$0 $_key - `hget CMD_DESC $_key`"
done
exit 0
else
cmd=`hget CMD_LIST $_arg`
echo "Run $cmd"
eval $cmd
result=$?
if [ $result -ne 0 ]; then
exitCode=$result
fi
fi
done
exit $exitCode