Skip to content

Commit f5e24b7

Browse files
vikahltianon
authored andcommitted
Dynamically load Setuptools and Pip versions from ensurepip
The lookup table contained older versions of setuptools than what was configured in ensurepip for the given version. By dynamically loading the versions, it is guaranteed to keep in sync.
1 parent d27f3d2 commit f5e24b7

File tree

2 files changed

+33
-45
lines changed

2 files changed

+33
-45
lines changed

versions.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "21.2.4"
77
},
88
"setuptools": {
9-
"version": "57.5.0"
9+
"version": "58.1.0"
1010
},
1111
"variants": [
1212
"bullseye",
@@ -27,7 +27,7 @@
2727
"version": "21.2.4"
2828
},
2929
"setuptools": {
30-
"version": "57.5.0"
30+
"version": "58.1.0"
3131
},
3232
"variants": [
3333
"bullseye",
@@ -86,7 +86,7 @@
8686
"version": "21.2.4"
8787
},
8888
"setuptools": {
89-
"version": "57.5.0"
89+
"version": "58.1.0"
9090
},
9191
"variants": [
9292
"bullseye",

versions.sh

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,10 @@
22
set -Eeuo pipefail
33
shopt -s nullglob
44

5-
# TODO https://github.com/docker-library/python/pull/686
65
# https://github.com/docker-library/python/issues/365
7-
# https://pypi.org/project/pip/#history
8-
declare -A pipVersions=(
9-
[3.11]='21.2' # https://github.com/python/cpython/blob/v3.11.0a1/Lib/ensurepip/__init__.py -- "_PIP_VERSION"
10-
[3.10]='21.2' # https://github.com/python/cpython/blob/3.10/Lib/ensurepip/__init__.py -- "_PIP_VERSION"
11-
[3.9]='21.2' # https://github.com/python/cpython/blob/3.9/Lib/ensurepip/__init__.py -- "_PIP_VERSION"
12-
[3.8]='21.2' # historical
13-
[3.7]='21.2' # historical
14-
)
15-
# https://pypi.org/project/setuptools/#history
16-
declare -A setuptoolsVersions=(
17-
[3.11]='57' # https://github.com/python/cpython/blob/v3.11.0a1/Lib/ensurepip/__init__.py -- "_SETUPTOOLS_VERSION"
18-
[3.10]='57' # https://github.com/python/cpython/blob/3.10/Lib/ensurepip/__init__.py -- "_SETUPTOOLS_VERSION"
19-
[3.9]='57' # https://github.com/python/cpython/blob/3.9/Lib/ensurepip/__init__.py -- "_SETUPTOOLS_VERSION"
20-
[3.8]='57' # historical
21-
[3.7]='57' # historical
22-
)
23-
# https://pypi.org/project/wheel/#history
24-
# TODO wheelVersions: https://github.com/docker-library/python/issues/365#issuecomment-914669320
6+
minimumPipVersion='21.2.4'
7+
minimumSetuptoolsVersion='57.5.0'
8+
# for historical reasons, these get pinned to either the version bundled with each Python version or these, whichever is higher
259

2610
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
2711

@@ -34,9 +18,6 @@ else
3418
fi
3519
versions=( "${versions[@]%/}" )
3620

37-
pipJson="$(curl -fsSL 'https://pypi.org/pypi/pip/json')"
38-
setuptoolsJson="$(curl -fsSL 'https://pypi.org/pypi/setuptools/json')"
39-
4021
getPipCommit="$(curl -fsSL 'https://github.com/pypa/get-pip/commits/main/public/get-pip.py.atom' | tac|tac | awk -F '[[:space:]]*[<>/]+' '$2 == "id" && $3 ~ /Commit/ { print $4; exit }')"
4122
getPipUrl="https://github.com/pypa/get-pip/raw/$getPipCommit/public/get-pip.py"
4223
getPipSha256="$(curl -fsSL "$getPipUrl" | sha256sum | cut -d' ' -f1)"
@@ -139,31 +120,38 @@ for version in "${versions[@]}"; do
139120
exit 1
140121
fi
141122

142-
pipVersion="${pipVersions[$rcVersion]}"
123+
ensurepipVersions="$(
124+
wget -qO- "https://github.com/python/cpython/raw/v$fullVersion/Lib/ensurepip/__init__.py" \
125+
| grep -E '^[^[:space:]]+_VERSION[[:space:]]*='
126+
)"
127+
pipVersion="$(sed -nre 's/^_PIP_VERSION[[:space:]]*=[[:space:]]*"(.*?)".*/\1/p' <<<"$ensurepipVersions")"
128+
setuptoolsVersion="$(sed -nre 's/^_SETUPTOOLS_VERSION[[:space:]]*=[[:space:]]*"(.*?)".*/\1/p' <<<"$ensurepipVersions")"
129+
# make sure we got something
130+
if [ -z "$pipVersion" ] || [ -z "$setuptoolsVersion" ]; then
131+
echo >&2 "error: $version: missing either pip ($pipVersion) or setuptools ($setuptoolsVersion) version"
132+
exit 1
133+
fi
134+
# make sure what we got is valid versions
135+
if ! wget -q -O /dev/null -o /dev/null --spider "https://pypi.org/pypi/pip/$pipVersion/json" || ! wget -q -O /dev/null -o /dev/null --spider "https://pypi.org/pypi/setuptools/$setuptoolsVersion/json"; then
136+
echo >&2 "error: $version: either pip ($pipVersion) or setuptools ($setuptoolsVersion) version seems to be invalid?"
137+
exit 1
138+
fi
139+
143140
pipVersion="$(
144-
export pipVersion
145-
jq <<<"$pipJson" -r '
146-
.releases
147-
| [
148-
keys_unsorted[]
149-
| select(. == env.pipVersion or startswith(env.pipVersion + "."))
150-
]
151-
| max_by(split(".") | map(tonumber))
152-
'
141+
{
142+
echo "$pipVersion"
143+
echo "$minimumPipVersion"
144+
} | sort -rV | head -1
153145
)"
154-
setuptoolsVersion="${setuptoolsVersions[$rcVersion]}"
155146
setuptoolsVersion="$(
156-
export setuptoolsVersion
157-
jq <<<"$setuptoolsJson" -r '
158-
.releases
159-
| [
160-
keys_unsorted[]
161-
| select(. == env.setuptoolsVersion or startswith(env.setuptoolsVersion + "."))
162-
]
163-
| max_by(split(".") | map(tonumber))
164-
'
147+
{
148+
echo "$setuptoolsVersion"
149+
echo "$minimumSetuptoolsVersion"
150+
} | sort -rV | head -1
165151
)"
166152

153+
# TODO wheelVersion, somehow: https://github.com/docker-library/python/issues/365#issuecomment-914669320
154+
167155
echo "$version: $fullVersion (pip $pipVersion, setuptools $setuptoolsVersion${hasWindows:+, windows})"
168156

169157
export fullVersion pipVersion setuptoolsVersion hasWindows

0 commit comments

Comments
 (0)