-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
executable file
·128 lines (109 loc) · 3.5 KB
/
run
File metadata and controls
executable file
·128 lines (109 loc) · 3.5 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
# ABOUT: helper command line launcher script for common project
# operations encapsulating from technology & environment details.
# Ensure using local venv libraries.
if [[ "${VIRTUAL_ENV}" == "" ]]; then
if [ -d ".venv" ]; then
source ".venv/bin/activate";
else
echo "Need a virtual environment to activate";
exit 1;
fi;
fi
# Listen for ctrl-c signals & forward to child processes.
trap 'pkill -P ${$};' SIGINT;
# ABOUT: display usage of specific or all known commands.
function fn_help() {
local app; app=$(basename "${0}");
local format=' %s%20s\n';
echo "USAGE:";
if [ ${1:-'install'} == 'install' ]; then
printf "${format}" "${app} --install; # install dependencies";
fi;
if [ ${1:-'build'} == 'build' ]; then
printf "${format}" "${app} --build; # compile & packages code";
fi;
if [ ${1:-'doc'} == 'doc' ]; then
printf "${format}" "${app} --doc; # generate documentation";
fi;
if [ ${1:-'test'} == 'test' ]; then
printf "${format}" "${app} --test <path/test_*.py>; # perform unit & integration tests";
fi;
if [ ${1:-'repl'} == 'repl' ]; then
printf "${format}" "${app} --repl # launch a python console";
fi;
if [ ${1:-'deploy'} == 'deploy' ]; then
printf "${format}" "${app} --deploy; # deploy packages";
fi;
if [ ${1:-'all'} == 'all' ]; then
printf "${format}" "${app} --all; # end-to-end flow";
fi;
exit 0;
}
# ABOUT: installs all dependencies into local environment
function fn_install() {
echo -e ">> Installing dependencies into: ${VIRTUAL_ENV}";
for req in requirements/requirements_*.txt; do
pip install -r "${req}" "${@}";
done
}
# ABOUT: cythonizes respective code modules & packages them
function fn_build() {
echo -e ">> Building project ..";
local build_dir="/tmp";
python setup.py clean && \
python setup.py build_ext \
-b "${build_dir}" \
-t "${build_dir}" \
--inplace \
--parallel "$(sysctl -n hw.ncpu || echo 1)" \
--force \
--quiet &&
python setup.py sdist egg_info --egg-base "${build_dir}";
}
# ABOUT: execute quality control
function fn_test() {
echo -e ">> Running test suite ..";
pytest \
-c=tests/code_tests.cfg --cov \
--cov-config=tests/code_coverage.cfg \
--benchmark-storage=runtime/code_benchmarks
"${@}";
}
# ABOUT: launch a python console to run custom code same as the system would.
function fn_repl() {
python "${@}";
}
# ABOUT: build technical documentation
function fn_document() {
echo -e ">> Documenting codebase ..";
mkdocs serve;
}
# ABOUT: public deploy package to python index
function fn_deploy() {
echo -e ">> Packaging project ..";
local PYPI_API_TOKEN='';
local PYPI_SERVER="pypi";
twine upload \
--username __token__ \
--password "${PYPI_API_TOKEN}" \
--repository "${PYPI_SERVER}" \
dist/*;
}
# Process commands
cmd=${1} && shift 1;
case ${cmd} in
--install | install) fn_install "${@}";;
--build | build) fn_build "${@}";;
--doc | doc) fn_document "${@}";;
--test | test) fn_test "${@}";;
--repl | repl) fn_repl "${@}";;
--deploy | deploy) fn_deploy "${@}";;
--all | all) fn_install && \
fn_build && \
fn_document && \
fn_test && \
fn_deploy;;
--help | help | *) fn_help "${@}";;
esac
exit 0;