-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
versions.sh
executable file
·195 lines (170 loc) · 5.33 KB
/
versions.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
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env bash
set -Eeuo pipefail
shopt -s nullglob
# https://github.com/docker-library/python/issues/365
minimumSetuptoolsVersion='57.5.0'
# for historical reasons, setuptools gets pinned to either the version bundled with each Python version or this, whichever is higher
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
has_linux_version() {
local dir="$1"; shift
local dirVersion="$1"; shift
local fullVersion="$1"; shift
if ! wget -q -O /dev/null -o /dev/null --spider "https://www.python.org/ftp/python/$dirVersion/Python-$fullVersion.tar.xz"; then
return 1
fi
return 0
}
has_windows_version() {
local dir="$1"; shift
local dirVersion="$1"; shift
local fullVersion="$1"; shift
if ! wget -q -O /dev/null -o /dev/null --spider "https://www.python.org/ftp/python/$dirVersion/python-$fullVersion-amd64.exe"; then
return 1
fi
return 0
}
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
export version rcVersion
rcGrepV='-v'
if [ "$rcVersion" != "$version" ]; then
rcGrepV=
fi
possibles=( $(
{
git ls-remote --tags https://github.com/python/cpython.git "refs/tags/v${rcVersion}.*" \
| sed -r 's!^.*refs/tags/v([0-9a-z.]+).*$!\1!' \
| grep $rcGrepV -E -- '[a-zA-Z]+' \
|| :
# this page has a very aggressive varnish cache in front of it, which is why we also scrape tags from GitHub
wget -qO- 'https://www.python.org/ftp/python/' \
| grep '<a href="'"$rcVersion." \
| sed -r 's!.*<a href="([^"/]+)/?".*!\1!' \
| grep $rcGrepV -E -- '[a-zA-Z]+' \
|| :
} | sort -ruV
) )
fullVersion=
hasWindows=
declare -A impossible=()
for possible in "${possibles[@]}"; do
rcPossible="${possible%%[a-z]*}"
# varnish is great until it isn't (usually the directory listing we scrape below is updated/uncached significantly later than the release being available)
if has_linux_version "$version" "$rcPossible" "$possible"; then
fullVersion="$possible"
if has_windows_version "$version" "$rcPossible" "$possible"; then
hasWindows=1
fi
break
fi
if [ -n "${impossible[$rcPossible]:-}" ]; then
continue
fi
impossible[$rcPossible]=1
possibleVersions=( $(
wget -qO- -o /dev/null "https://www.python.org/ftp/python/$rcPossible/" \
| grep '<a href="Python-'"$rcVersion"'.*\.tar\.xz"' \
| sed -r 's!.*<a href="Python-([^"/]+)\.tar\.xz".*!\1!' \
| grep $rcGrepV -E -- '[a-zA-Z]+' \
| sort -rV \
|| true
) )
for possibleVersion in "${possibleVersions[@]}"; do
if has_linux_version "$version" "$rcPossible" "$possibleVersion"; then
fullVersion="$possibleVersion"
if has_windows_version "$version" "$rcPossible" "$possible"; then
hasWindows=1
fi
break
fi
done
done
if [ -z "$fullVersion" ]; then
{
echo
echo
echo " error: cannot find $version (alpha/beta/rc?)"
echo
echo
} >&2
exit 1
fi
ensurepipVersions="$(
wget -qO- "https://github.com/python/cpython/raw/v$fullVersion/Lib/ensurepip/__init__.py" \
| grep -E '^[^[:space:]]+_VERSION[[:space:]]*='
)"
# Note: We don't extract the pip version here, since our policy is now to use the pip version
# that is installed during the Python build (which is the version bundled in ensurepip), and
# to not support overriding it.
# TODO remove setuptools version handling entirely once Python 3.11 is EOL
setuptoolsVersion="$(sed -nre 's/^_SETUPTOOLS_VERSION[[:space:]]*=[[:space:]]*"(.*?)".*/\1/p' <<<"$ensurepipVersions")"
case "$rcVersion" in
3.8 | 3.9 | 3.10 | 3.11)
if [ -z "$setuptoolsVersion" ]; then
echo >&2 "error: $version: missing setuptools version"
exit 1
fi
if ! wget -q -O /dev/null -o /dev/null --spider "https://pypi.org/pypi/setuptools/$setuptoolsVersion/json"; then
echo >&2 "error: $version: setuptools version ($setuptoolsVersion) seems to be invalid?"
exit 1
fi
# TODO remove this once Python 3.8 is either "new enough setuptools" or EOL
setuptoolsVersion="$(
{
echo "$setuptoolsVersion"
echo "$minimumSetuptoolsVersion"
} | sort -rV | head -1
)"
# https://github.com/docker-library/python/issues/781 (TODO remove this if 3.10 and 3.11 embed a newer setuptools and this section no longer applies)
if [ "$setuptoolsVersion" = '65.5.0' ]; then
setuptoolsVersion='65.5.1'
fi
;;
*)
# https://github.com/python/cpython/issues/95299 -> https://github.com/python/cpython/commit/ece20dba120a1a4745721c49f8d7389d4b1ee2a7
if [ -n "$setuptoolsVersion" ]; then
echo >&2 "error: $version: unexpected setuptools: $setuptoolsVersion"
exit 1
fi
;;
esac
echo "$version: $fullVersion"
export fullVersion pipVersion setuptoolsVersion hasWindows
json="$(jq <<<"$json" -c '
.[env.version] = {
version: env.fullVersion,
variants: [
(
"bookworm",
"bullseye",
empty
| ., "slim-" + .), # https://github.com/docker-library/ruby/pull/142#issuecomment-320012893
(
"3.20",
"3.19",
empty
| "alpine" + .),
if env.hasWindows != "" then
(
"ltsc2022",
"1809",
empty
| "windows/windowsservercore-" + .)
else empty end
],
} + if env.setuptoolsVersion != "" then {
setuptools: {
version: env.setuptoolsVersion,
},
} else {} end
')"
done
jq <<<"$json" -S . > versions.json