-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-install.sh
executable file
·163 lines (133 loc) · 3.87 KB
/
build-install.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
#!/usr/bin/env bash
#
# uninstall, build, install, run
#
# This script does not pip install any other package.
# Requires python modules:
# pip
# wheel
# twine
# setuptools
#
# caller can override $PYTHON
#
# Manually tested to run under differing environments including:
# Python 3.7 on MinGW64 shell on Windows 10
# Python 3.5.3 on Debian 9 Stretch Linux on WLS
# Python 3.6.5 on OpenSUSE 15 Leap Linux on WLS
# Python 3.5 on Debian 9 Stretch Linux on Raspberry Pi
#
# XXX: very similar to .circleci/build-install-run.sh
# XXX: very similar to .azure-pipelines/build-install-run.sh
set -e
set -u
set -o pipefail
cd "$(dirname -- "${0}")/.." # cd to project top-level
#
# make a good effort to get the path to the local python 3 installation
# if $PTYHON is set, assume it's the PYTHON interpreter
#
if [[ ! "${PYTHON+x}" ]]; then
# attempt to set python to most portable invocation
PYTHON='python' # fallback
if which 'python3' &> /dev/null; then
PYTHON='python3' # Linux Python 3
elif which 'py.exe' &> /dev/null; then
PYTHON='py.exe' # Windows launcher, used by MinGW
fi
fi
# check $PYTHON runs
which ${PYTHON}
${PYTHON} --version
#
# build package
#
readonly PACKAGE_NAME='goto_http_redirect_server'
readonly PROGRAM_NAME='goto_http_redirect_server'
# mypy check first
${PYTHON} -m mypy 'goto_http_redirect_server/goto_http_redirect_server.py'
# Debian bash on Windows Linux Subsystem may not have default pip install path
if [[ -d ~/.local/bin ]]; then
export PATH=${PATH}:~/.local/bin
fi
set -x
${PYTHON} -m pip list -vvv
# uninstall any previous install (must be done outside the project directory)
cd ..
${PYTHON} -m pip uninstall --yes --verbose "${PACKAGE_NAME}" || true
# remove previous build artifacts
rm -rfv ./build/ ./dist/ "./${PACKAGE_NAME}.egg-info/"
# build using wheels
cd -
version=$(${PYTHON} -B -c 'from goto_http_redirect_server import goto_http_redirect_server as gh;print(gh.__version__)')
source ./tools/ci/PATH-add-pip-site.sh
${PYTHON} setup.py -v bdist_wheel
# note the contents of dist
ls -l ./dist/
set +x
# get the full path to the wheel file
# (usually, `basename $PWD` is 'goto_http_redirect_server' but on circleci it's 'project')
cv_whl=$(readlink -f -- "./dist/${PACKAGE_NAME}-${version}-py3-none-any.whl") || true
if ! [[ -f "${cv_whl}" ]]; then
cv_whl=$(readlink -f -- "./dist/${PACKAGE_NAME}-${version}-py3.7-none-any.whl") || true
fi
if ! [[ -f "${cv_whl}" ]]; then
echo "ERROR: could not find expected wheel file at './dist/${PACKAGE_NAME}-${version}-py3-none-any.whl'" >&2
exit 1
fi
(
set -x
${PYTHON} -m twine --version
${PYTHON} -m twine check "${cv_whl}"
)
# install the wheel (must be done outside the project directory)
(
cd ..
user_arg=--user
if [[ "${VIRTUAL_ENV+x}" ]]; then # if virtualenv then do not pass --user
user_arg=''
fi
set -x
${PYTHON} -m pip install --disable-pip-version-check ${user_arg} --verbose "${cv_whl}"
)
# make sure to attempt uninstall if asked
uninstall=false
if [[ "${1+x}" == '--uninstall' ]]; then
uninstall=true
fi
function on_exit(){
if ${uninstall}; then
set -x
${PYTHON} -m pip uninstall --yes --verbose "${PACKAGE_NAME}"
fi
}
trap on_exit EXIT
SERVER_TEST=$(readlink -f -- "./tools/ci/server-test.sh")
(
set -x
# does it run?
"${PACKAGE_NAME}" --version
"${SERVER_TEST}"
)
#
# exit with hint
#
if ${uninstall}; then
# and test uninstall if asked
(
set -x
${PYTHON} -m pip uninstall --yes --verbose "${PACKAGE_NAME}"
)
# if script got here then no need to run uninstall on EXIT
uninstall=false
else
echo "
To uninstall remaining package:
(cd ..; ${PYTHON} -m pip uninstall --yes --verbose '${PACKAGE_NAME}')
or run this script with '--uninstall'
"
fi
echo "Success!
To upload to pypi:
${PYTHON} -m twine upload --verbose '${cv_whl}'
"