forked from docker-library/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversions.sh
executable file
·215 lines (189 loc) · 6.25 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/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[@]%/}" )
getPipCommit="$(curl -fsSL 'https://github.com/pypa/get-pip/commits/main/public/get-pip.py.atom' | grep -E 'id.*Commit')"
getPipCommit="$(awk <<<"$getPipCommit" -F '[[:space:]]*[<>/]+' '$2 == "id" && $3 ~ /Commit/ { print $4; exit }')"
getPipUrl="https://github.com/pypa/get-pip/raw/$getPipCommit/public/get-pip.py"
getPipSha256="$(curl -fsSL "$getPipUrl" | sha256sum | cut -d' ' -f1)"
export getPipCommit getPipUrl getPipSha256
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
curl -fsSL '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:]]*='
)"
pipVersion="$(sed -nre 's/^_PIP_VERSION[[:space:]]*=[[:space:]]*"(.*?)".*/\1/p' <<<"$ensurepipVersions")"
if [ -z "$pipVersion" ]; then
echo >&2 "error: $version: missing pip version"
exit 1
fi
if ! wget -q -O /dev/null -o /dev/null --spider "https://pypi.org/pypi/pip/$pipVersion/json"; then
echo >&2 "error: $version: pip version ($pipVersion) seems to be invalid?"
exit 1
fi
setuptoolsVersion="$(sed -nre 's/^_SETUPTOOLS_VERSION[[:space:]]*=[[:space:]]*"(.*?)".*/\1/p' <<<"$ensurepipVersions")"
case "$rcVersion" in
3.7 | 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.7 and 3.8 are 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
# TODO wheelVersion, somehow: https://github.com/docker-library/python/issues/365#issuecomment-914669320
echo "$version: $fullVersion (pip $pipVersion${setuptoolsVersion:+, setuptools $setuptoolsVersion}${hasWindows:+, windows})"
export fullVersion pipVersion setuptoolsVersion hasWindows
json="$(jq <<<"$json" -c '
.[env.version] = {
version: env.fullVersion,
pip: {
version: env.pipVersion,
},
"get-pip": {
version: "https://github.com/pypa/get-pip/commit/\(env.getPipCommit)",
url: env.getPipUrl,
sha256: env.getPipSha256,
},
variants: [
(
"bookworm",
"bullseye",
empty
| ., "slim-" + .), # https://github.com/docker-library/ruby/pull/142#issuecomment-320012893
(
"3.18",
"3.17",
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