Skip to content

Commit 0c43fbc

Browse files
committed
Simplify pypi_publish.sh's version-comparison logic
The old code interpolated published_version — fetched from PyPI's JSON API, so not under our control — into a second python -c string via bash substitution. A version string containing a quote or backslash would break out of the embedded snippet. Doing the fetch and comparison in one python3 invocation drops that interpolation entirely.
1 parent e2cff6e commit 0c43fbc

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

scripts/pypi_publish.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,13 @@ else
3535
# but PyPI/TestPyPI support registering a *pending* trusted publisher for
3636
# a project that doesn't exist yet, so the first publish can go out
3737
# through this same automated path.
38-
published_version=$(curl -sf "$JSON_HOST/$name/json" | python3 -c "import json,sys; print(json.load(sys.stdin)['info']['version'])" 2>/dev/null) || {
38+
published_version=$(curl -sf "$JSON_HOST/$name/json" | jq -r '.info.version') || published_version=""
39+
40+
if [ -z "$published_version" ]; then
3941
echo "Will publish $name: first publish ($repo_version)"
4042
TO_PUBLISH+=("$name:$repo_version")
41-
continue
42-
}
43-
44-
# Assumes plain X.Y.Z versions, matching this workspace's packages.
45-
is_newer=$(python3 -c "
46-
a = tuple(int(x) for x in '$repo_version'.split('.')[:3])
47-
b = tuple(int(x) for x in '$published_version'.split('.')[:3])
48-
print(a > b)
49-
")
50-
if [ "$is_newer" = "True" ]; then
43+
elif [ "$repo_version" != "$published_version" ] &&
44+
[ "$(printf '%s\n%s\n' "$repo_version" "$published_version" | sort -V | tail -1)" = "$repo_version" ]; then
5145
echo "Will publish $name: $published_version$repo_version"
5246
TO_PUBLISH+=("$name:$repo_version")
5347
else

0 commit comments

Comments
 (0)