Here is a revision of the patch, so that py-compile-en.sh test passes. Here's another attempt at the patch, calling $PYTHON -V instead of using the name of $0 to decide if it's really Python. Wdyt?
The result is that $PYTHON can be set to anything at all and py-compile will succeed. Since the goal is to support "disabling" via PYTHON=:. I can't see how to reasonably support the previous behavior of PYTHON=: succeeding and PYTHON=false failing, unless we make a special case for : (and true and ...?), which seems undesirable. Do you (or anyone) think we need to worry about this, or is it ok for py-compile to now succeed with any value of $PYTHON? I worry people assumed the previous bizarre behavior in their Makefiles. Thanks, Karl diff --git a/lib/py-compile b/lib/py-compile index 9659beca6..d68a4431e 100755 --- a/lib/py-compile +++ b/lib/py-compile @@ -33,6 +33,15 @@ fi me=py-compile +# People apparently set PYTHON=: and expect the result to be true. +# This means setting PYTHON=false will also exit true, but what can we do? +# For the same reason, we output to stdout instead of stderr. Bizarre. +if $PYTHON -V 2>/dev/null | grep -i python; then :; else + echo "$me: Invalid python executable (according to -V): $PYTHON" + echo "$me: Python support disabled" + exit 0 +fi + usage_error () { echo "$me: $*" >&2 diff --git a/t/py-compile-env.sh b/t/py-compile-env.sh index 564fb98c6..fc82df43a 100644 --- a/t/py-compile-env.sh +++ b/t/py-compile-env.sh @@ -31,7 +31,13 @@ chmod a+x my-py mkdir sub1 cd sub1 -PYTHON=false ../py-compile foo.py && exit 1 +# This should succeed and do nothing. +PYTHON=: ../py-compile foo.py +ls | grep . && exit 1 + +# This command will also succeed, since we intentionally allow PYTHON to +# be set to anything. +PYTHON=false ../py-compile foo.py ls | grep . && exit 1 PYTHON='echo GrEpMe AndMeToo' ../py-compile foo.py compile finished at Mon Feb 3 10:04:09 2025