Skip to content

Commit 15901c1

Browse files
committed
fix(release): resolve lazily, and do not swallow the not-found message
Resolving at load time made the interpreter a hard requirement for every invocation, including the ones that never run Python. On a machine with python3 3.9 and no uv, `--help` died with the interpreter error instead of printing usage -- so the message telling you which interpreter you need was itself gated on having it, on exactly the machine the resolution exists for. Now resolved as the first line of cmd_prepare and cmd_publish, with an empty default for set -u. And `$(python3 -V 2>&1 || echo absent)` captured the shell's own "command not found" into the message before appending "absent", so the no-python3-at-all case printed both. Guarded on command -v. Verified: --help prints usage with PATH=/usr/bin:/bin; prepare/publish still refuse with `python3 is Python 3.9.6`; and with python3 entirely absent the message is `python3 is absent`.
1 parent f6fb736 commit 15901c1

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎scripts/release.sh‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ resolve_python() {
2121
elif command -v uv >/dev/null 2>&1; then
2222
echo "uv run --no-project --python 3.12 python"
2323
else
24-
die "need python3 >= 3.11 (for tomllib) or uv; python3 is $(python3 -V 2>&1 || echo absent)"
24+
die "need python3 >= 3.11 (for tomllib) or uv; python3 is $(command -v python3 >/dev/null 2>&1 && python3 -V 2>&1 || echo absent)"
2525
fi
2626
}
27-
PY_BIN="$(resolve_python)"
27+
28+
# Deferred, not resolved at load: the commands that never touch Python must keep
29+
# working without a usable interpreter — otherwise the message telling you which
30+
# interpreter you need is itself gated on having it, and `--help` breaks on
31+
# exactly the machine this resolution exists for. Empty default satisfies `set -u`
32+
# if a helper is ever reached by another path.
33+
PY_BIN=""
2834

2935
usage() {
3036
cat <<'EOF'
@@ -118,6 +124,7 @@ update_changelog() {
118124
}
119125

120126
cmd_prepare() {
127+
PY_BIN="$(resolve_python)"
121128
local bump="${1:-}"
122129
[[ -n "$bump" ]] || { usage; die "missing bump kind or explicit version"; }
123130
need gh
@@ -168,6 +175,7 @@ After merge, run \`./scripts/release.sh publish\` from a clean \`${base}\` check
168175
}
169176

170177
cmd_publish() {
178+
PY_BIN="$(resolve_python)"
171179
need gh
172180
ensure_clean
173181

0 commit comments

Comments
 (0)