Skip to content

Commit f6fb736

Browse files
committed
fix(release): resolve an interpreter that has tomllib
`./scripts/release.sh prepare minor` fails outright on macOS: ModuleNotFoundError: No module named 'tomllib' tomllib is stdlib only from 3.11, and `python3` on macOS is 3.9. Every helper in the script -- get_version, get_pkg_name, set_version, bump_version, the changelog update, and the publish-time changelog check -- hardcoded `python3`, so releasing this package was impossible on such a machine. The error names a missing module, which reads as a broken checkout rather than a too-old interpreter. Resolved once at load time instead of per call site: `python3` when it can actually import tomllib, else `uv run`, else a message that says what is needed and what was found. uv is the right fallback because this repo already builds and tests through it, so a machine that can run the suite can run the release. The two `need python3` guards are dropped as redundant -- resolve_python has already exited with a better message by then. Verified under bash, which is how the script runs: PY_BIN=uv run --no-project --python 3.12 python version=0.10.0 pkg=hotdata-framework minor=0.11.0 patch=0.10.1 major=1.0.0 and with no usable interpreter on PATH: error: need python3 >= 3.11 (for tomllib) or uv; python3 is Python 3.9.6 No behaviour change to what a release does -- only which interpreter runs it. Note the same hardcoded `python3 - <<PY` + tomllib pattern is in sdk-python's and hotdata-marimo's copies of this script, so both are latently broken the same way on a pre-3.11 `python3`. Not touched here.
1 parent d1d6a1c commit f6fb736

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

scripts/release.sh

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ cd "$ROOT"
77
die() { echo "error: $*" >&2; exit 1; }
88
need() { command -v "$1" >/dev/null 2>&1 || die "$1 is required"; }
99

10+
# An interpreter that can `import tomllib` — stdlib only from 3.11, while
11+
# `python3` on macOS is still 3.9. Hardcoding `python3` made every step below
12+
# fail with a bare ModuleNotFoundError, which reads as a broken checkout rather
13+
# than a too-old interpreter, and it failed at the FIRST step so nothing was
14+
# half-done. Resolved once here rather than per call site.
15+
#
16+
# `uv` is the fallback because this repo already builds and tests through it, so
17+
# a machine that can run the suite can run the release.
18+
resolve_python() {
19+
if command -v python3 >/dev/null 2>&1 && python3 -c "import tomllib" >/dev/null 2>&1; then
20+
echo python3
21+
elif command -v uv >/dev/null 2>&1; then
22+
echo "uv run --no-project --python 3.12 python"
23+
else
24+
die "need python3 >= 3.11 (for tomllib) or uv; python3 is $(python3 -V 2>&1 || echo absent)"
25+
fi
26+
}
27+
PY_BIN="$(resolve_python)"
28+
1029
usage() {
1130
cat <<'EOF'
1231
Usage:
@@ -24,15 +43,15 @@ EOF
2443
}
2544

2645
get_version() {
27-
python3 - <<'PY'
46+
$PY_BIN - <<'PY'
2847
import tomllib
2948
from pathlib import Path
3049
print(tomllib.loads(Path("pyproject.toml").read_text())["project"]["version"])
3150
PY
3251
}
3352

3453
get_pkg_name() {
35-
python3 - <<'PY'
54+
$PY_BIN - <<'PY'
3655
import tomllib
3756
from pathlib import Path
3857
print(tomllib.loads(Path("pyproject.toml").read_text())["project"]["name"])
@@ -41,7 +60,7 @@ PY
4160

4261
set_version() {
4362
local ver="$1"
44-
python3 - "$ver" <<'PY'
63+
$PY_BIN - "$ver" <<'PY'
4564
import re, sys
4665
from pathlib import Path
4766
ver = sys.argv[1]
@@ -56,7 +75,7 @@ PY
5675

5776
bump_version() {
5877
local kind="$1" current="$2"
59-
python3 - "$kind" "$current" <<'PY'
78+
$PY_BIN - "$kind" "$current" <<'PY'
6079
import re, sys
6180
kind, current = sys.argv[1], sys.argv[2]
6281
match = re.match(r"^(\d+)\.(\d+)\.(\d+)(.*)$", current)
@@ -95,14 +114,13 @@ update_changelog() {
95114
local ver="$1"
96115
local date
97116
date="$(date +%Y-%m-%d)"
98-
python3 scripts/update_changelog.py "$ver" "$date"
117+
$PY_BIN scripts/update_changelog.py "$ver" "$date"
99118
}
100119

101120
cmd_prepare() {
102121
local bump="${1:-}"
103122
[[ -n "$bump" ]] || { usage; die "missing bump kind or explicit version"; }
104123
need gh
105-
need python3
106124
ensure_clean
107125

108126
local current new base branch pkg
@@ -151,7 +169,6 @@ After merge, run \`./scripts/release.sh publish\` from a clean \`${base}\` check
151169

152170
cmd_publish() {
153171
need gh
154-
need python3
155172
ensure_clean
156173

157174
local base ver tag
@@ -166,7 +183,7 @@ cmd_publish() {
166183

167184
git rev-parse "$tag" >/dev/null 2>&1 && die "tag $tag already exists"
168185
[[ -f CHANGELOG.md ]] || die "CHANGELOG.md is required"
169-
python3 - "$ver" <<'PY'
186+
$PY_BIN - "$ver" <<'PY'
170187
import re, sys
171188
from pathlib import Path
172189
ver = sys.argv[1]

0 commit comments

Comments
 (0)