-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test
executable file
·107 lines (94 loc) · 3.58 KB
/
Test
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
#!/usr/bin/env bash
set -euo pipefail
pythonz=~/.pythonz/bin/pythonz
pythonz_url='https://raw.github.com/saghul/pythonz/master/pythonz-install'
####################################################################
# Functions
die() {
local exitcode="$1"; shift
echo 1>&2 "ERROR:" "$@"
exit $exitcode
}
tox_python_versions() {
# Extract a list of all Python versions (major.minor number only)
# that tox.ini is testing. `tox -a` will return a list of all
# combinations like `py3.11-pytest8`; for all lines starting
# with `pyM.n` we extract just the `M.n` and print the unique
# values in sorted order.
tox -a | sed -n -e '/^py.*-pytest/{ s/^py//; s/-.*//; p }' \
| sort -t . -k 2 -n | uniq
}
pythonz_versions() {
# For each version number M.n in $(tox_python_versions), find
# the latest version that pythonz knows about (whether installed
# or not), which will be in M.n.p format. (This is somewhat slow.)
for v in $(tox_python_versions); do
lastver=$(
pythonz list -t cpython -a \
| sed -n -e '/^ *[0-9]/s/^ *//p' \
| grep -F "$v." \
| sort -t . -k 3 -n \
| tail -1
) || true
[[ -z $lastver ]] && die 4 "Can't find Python version matching $v"
echo -n "$lastver" ' '
done
}
build_pythons() {
# Install pythonz and Python build dependencies, if necessary, or
# update pythonz to the latest version if that's not been done within
# the last 24 hours.
#
# Then have pythonz download and build all Python versions in
# $(pythonz_versions). Any already built will simply produce a
# notice from pythonz that it's already there.
#
if [[ -x "$pythonz" ]]; then
# If pythonz is already installed, we assume that all the OS
# dependencies necessary to build working Pythons are intalled.
tsfile="$PROJDIR/.build/pythonz-update-timestamp"
touch -d '24 hours ago' "$tsfile"
[[ $pythonz -ot $tsfile ]] && { # pythonz more than a day old?
echo "===== Updating pythonz"
"$pythonz" update
}
else
echo "===== Installing Python build dependencies"
# Also apt-get build dependencies as per "From Source" below:
if type -p apt-get >/dev/null; then
sudo apt-get install build-essential dpkg-dev \
libffi-dev zlib1g-dev libbz2-dev liblzma-dev \
libssl-dev libgdbm-dev libncurses5-dev libreadline-dev
else
die 3 "Don't know how to install Python build dependencies"
fi
echo "===== Installing pythonz"
curl -sS -kL "$pythonz_url" | bash
fi
echo "===== Building Pythons"
for v in $(pythonz_versions); do
echo "----- Building Python $v"
"$pythonz" install -t cpython "$v"
done
echo "===== Python builds completed"
}
test_tox() {
for v in $(pythonz_versions); do
# Horrible hack to get tox to be able to use our pythonz Pythons.
PATH="$(dirname "$("$pythonz" locate $v)")":"$PATH"
done
tox "$@"
}
####################################################################
# Main
PROJDIR=$(cd "$(dirname "$0")" && pwd -P)
cd "$PROJDIR"
# If first arg is -B we build pythonz interpreters.
build_pythons_opt=false
[[ ${#@} -gt 0 ]] && [[ $1 == -B ]] && { shift; build_pythons_opt=true; }
# Remaining args passed on to tox
[[ -x "$pythonz" ]] \
|| die 3 "$pythonz not found; use ./Test -B to build Pythons"
. ./pactivate -q
$build_pythons_opt && build_pythons
test_tox "$@"