-
Notifications
You must be signed in to change notification settings - Fork 8
/
build_all.sh
executable file
·182 lines (168 loc) · 5.51 KB
/
build_all.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
#
# Builds orderedstructs for distribution
# Ref: https://packaging.python.org/tutorials/packaging-projects/
#
# Other references:
# https://kvz.io/bash-best-practices.html
# https://bertvv.github.io/cheat-sheets/Bash.html
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
# Takes about 5 to 10 minutes per Python version.
# See: https://devguide.python.org/versions/
PYTHON_VERSIONS=('3.8' '3.9' '3.10' '3.11' '3.12' '3.13')
# Used for venvs
PYTHON_VENV_ROOT="${HOME}/pyenvs"
PROJECT_NAME="SkipList"
CPP_EXECUTABLE="SkipList"
#printf "%-8s %8s s s s\n" "Ext" "Files" "Lines" "Words" "Bytes"
build_cpp() {
cmake --build cmake-build-release --target clean -- -j 6
cmake --build cmake-build-release --target ${CPP_EXECUTABLE} -- -j 6
}
run_cpp_tests() {
cmake-build-release/${CPP_EXECUTABLE}
}
deactivate_virtual_environment() {
# https://stackoverflow.com/questions/42997258/virtualenv-activate-script-wont-run-in-bash-script-with-set-euo
set u
if command -v deactivate &>/dev/null; then
deactivate
fi
set -u
}
create_virtual_environments() {
deactivate_virtual_environment
for version in ${PYTHON_VERSIONS[*]}; do
echo "---> Create virtual environment for Python version ${version}"
venv_path="${PYTHON_VENV_ROOT}/${PROJECT_NAME}_${version}"
if [ ! -d "${venv_path}" ]; then
# Control will enter here if directory not exists.
echo "---> Creating virtual environment at: ${venv_path}"
"python${version}" -m venv "${venv_path}"
fi
done
}
remove_virtual_environments() {
deactivate_virtual_environment
for version in ${PYTHON_VERSIONS[*]}; do
echo "---> For Python version ${version}"
venv_path="${PYTHON_VENV_ROOT}/${PROJECT_NAME}_${version}"
if [ -d "${venv_path}" ]; then
# Control will enter here if directory exists.
echo "---> Removing virtual environment at: ${venv_path}"
rm -rf "${venv_path}"
fi
done
}
create_and_test_bdist_wheel() {
echo "---> Creating bdist_wheel for all versions..."
for version in ${PYTHON_VERSIONS[*]}; do
echo "---> For Python version ${version}"
deactivate_virtual_environment
venv_path="${PYTHON_VENV_ROOT}/${PROJECT_NAME}_${version}"
if [ ! -d "${venv_path}" ]; then
# Control will enter here if directory doesn't exist.
echo "---> Creating virtual environment at: ${venv_path}"
"python${version}" -m venv "${venv_path}"
fi
# https://stackoverflow.com/questions/42997258/virtualenv-activate-script-wont-run-in-bash-script-with-set-euo
set u
source "${venv_path}/bin/activate"
set -u
echo "---> Python version:"
python -VV
echo "---> Installing everything via pip:"
pip install -U pip setuptools wheel
pip install -r requirements.txt
# Needed for uploading to pypi
pip install twine
echo "---> Result of pip install:"
pip list
echo "---> Running python setup.py develop:"
# MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang python setup.py develop
python setup.py develop
echo "---> Running tests:"
# Fail fast with -x
pytest tests -x
# Run all tests (slow).
pytest tests --runslow --benchmark-sort=name --benchmark-autosave --benchmark-histogram
echo "---> Running setup for bdist_wheel:"
python setup.py bdist_wheel
done
}
create_sdist() {
echo "---> Running setup for sdist:"
python setup.py sdist
}
create_documentation() {
echo "---> Python version:"
which python
python -VV
echo "---> pip list:"
pip list
echo "---> Building documentation:"
cd docs
./build_docs.sh
cd ..
}
report_all_versions_and_setups() {
echo "---> Reporting all versions..."
for version in ${PYTHON_VERSIONS[*]}; do
echo "---> For Python version ${version}"
deactivate_virtual_environment
venv_path="${PYTHON_VENV_ROOT}/${PROJECT_NAME}_${version}"
if [ ! -d "${venv_path}" ]; then
# Control will enter here if directory doesn't exist.
echo "---> Creating virtual environment at: ${venv_path}"
"python${version}" -m venv "${venv_path}"
fi
echo "---> Virtual environment at: ${venv_path}"
# https://stackoverflow.com/questions/42997258/virtualenv-activate-script-wont-run-in-bash-script-with-set-euo
set u
source "${venv_path}/bin/activate"
set -u
echo "---> Python version:"
python -VV
echo "---> pip list:"
pip list
done
# Don't do this as we want to use show_results_of_dist() and twine after this
# deactivate_virtual_environment
}
show_results_of_dist() {
echo "---> dist/:"
ls -l "dist"
echo "---> twine check dist/*:"
twine check dist/*
# Test from Test PyPi
# pip install -i https://test.pypi.org/simple/orderedstructs
echo "---> Ready for upload to test PyPi:"
echo "---> pip install twine"
echo "---> twine upload --repository testpypi dist/*"
echo "---> Or PyPi:"
echo "---> twine upload dist/*"
}
echo "===> Clean and build C code"
build_cpp
echo "===> Running C tests"
run_cpp_tests
echo "===> Removing build/ and dist/"
rm -rf -- "build" "dist"
echo "===> Removing virtual environments"
remove_virtual_environments
echo "===> Creating virtual environments"
create_virtual_environments
echo "===> Creating binary wheels"
create_and_test_bdist_wheel
echo "===> Creating source distribution"
create_sdist
echo "===> All versions and setups:"
report_all_versions_and_setups
echo "===> Building documentation:"
create_documentation
echo "===> dist/ result:"
show_results_of_dist
#deactivate_virtual_environment
echo "===> All done"