-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_all.sh
executable file
·142 lines (131 loc) · 4.43 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
#!/bin/bash
#
# Builds cpip 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
PYTHON_VERSIONS=('3.7' '3.8' '3.9' '3.10' '3.11')
PYTHON_VENV_ROOT="${HOME}/pyenvs"
# Used for venvs
PROJECT_NAME="cpip"
#printf "%-8s %8s %10s %10s %12s\n" "Ext" "Files" "Lines" "Words" "Bytes"
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 --recursive --force -- "${venv_path}"
rm -rf -- "${venv_path}"
fi
done
}
create_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_dev.txt
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
echo "---> Running tests:"
# Fail fast with -x
pytest -x tests
echo "---> All tests pass for Python version ${version}"
echo "---> Running setup for bdist_wheel:"
python setup.py bdist_wheel
done
}
create_sdist() {
echo "---> Running setup for sdist:"
python setup.py sdist
}
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
}
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 "===> Removing build/ and dist/"
#rm --recursive --force -- "build" "dist"
rm -rf -- "build" "dist"
remove_virtual_environments
create_virtual_environments
create_bdist_wheel
create_sdist
report_all_versions_and_setups
pip install twine
show_results_of_dist
echo "===> All done"