GNU bug report logs -
#74434
[PATCH] py-compile: Allow user to disable python
Previous Next
Reported by: Frédéric Bérat <fberat <at> redhat.com>
Date: Tue, 19 Nov 2024 09:55:02 UTC
Severity: normal
Tags: patch
Done: Karl Berry <karl <at> freefriends.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Sun, 9 Feb 2025 10:36:47 -0700
with message-id <202502091736.519HalFW136227 <at> freefriends.org>
and subject line Re: [bug#74434] [PATCH] py-compile: Allow user to disable python
has caused the debbugs.gnu.org bug report #74434,
regarding [PATCH] py-compile: Allow user to disable python
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
74434: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=74434
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Hello,
While integrating automake 1.17, I found that otf2 package build fails.
The failure is due to:
py-compile: could not determine : major version
This is a side-effect of a rework of the py-compile script, which
formerly defaulted to python3 if there was an error while getting the
python version.
The new code doesn't have this fallback, and if users want to disable
python support by setting `PYTHON=:` as environment variable, the script
bails out.
I believe this is a common practice and that py-compile needs a fix. I
therefore propose the one below.
Feel free to tell me otherwise.
Fred.
-- 8< --
Subject: [PATCH] py-compile: Allow user to disable python
Common practice is to set PYTHON=: to disable python support, which
breaks the current version of this script.
Check that the PYTHON variable contains `python`, early exit otherwise.
---
lib/py-compile | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lib/py-compile b/lib/py-compile
index c9d4fde94..0238bab2c 100755
--- a/lib/py-compile
+++ b/lib/py-compile
@@ -33,6 +33,13 @@ fi
me=py-compile
+case "$PYTHON" in
+ *python*) ;;
+ *)
+ echo "$me: Python support disabled";
+ exit 0;;
+esac
+
usage_error ()
{
echo "$me: $*" >&2
--
2.47.0
[Message part 3 (message/rfc822, inline)]
Hi Frederic and all - I installed the following patch to py-compile.
Hopefully it restores the previous behavior of setting the PYTHON envvar
to whatever and "disabling" the compilation (but exiting succesfully).
Hope it flies, let me know if problems. --thanks, karl.
-----------------------------------------------------------------------------
python: restore more compatible behavior for $PYTHON.
For https://bugs.gnu.org/74434.
* lib/py-compile: if $PYTHON -V does not include the
string "python" (case-insensitive), consider the support
intentionally disabled and exit successfully, unless PYTHON is set
to false, in which case exit unsuccessfully. This is closer to
the old behavior. Mention this in the help message.
* t/py-compile-env.sh: add test for PYTHON=:.
* NEWS: mention this. (And, en passant, add some past bug#s and
clarify that only RCS/SCCS pattern rules were disabled, not all.)
diff --git a/NEWS b/NEWS
index f667c8727..22bd6a585 100644
--- a/NEWS
+++ b/NEWS
@@ -6,7 +6,7 @@ New in 1.x:
* New supported languages
- - Support for Algol 68 added, based on the GNU Algol 68 compiler.
+ - Support for Algol 68 added, based on the GNU Algol 68 compiler. (bug#75807)
* Miscellaneous changes
@@ -19,7 +19,14 @@ New in 1.x:
- Avoid Perl 5.41.8+ precedence warning for use of !!.
- - The compile script is more robust to various Windows configurations.
+ - The py-compile script once again does nothing (successfully) if the
+ PYTHON environment variable is set to ":", or anything that isn't a
+ Python interpreter (according to $PYTHON -V). Exception: if PYTHON
+ is set to "false", do nothing but exit unsuccessfully, also to match
+ previous behavior. (bug#74434)
+
+ - The compile script is more robust to Windows configurations;
+ specifically, avoiding double-path translation on MSYS. (bug#75939)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -51,8 +58,8 @@ New in 1.17:
retained when appended. GNU Make & BSD Makes are known to support it.
(bug#7610)
- - GNU Make's default pattern rules are disabled, for speed and debugging.
- (.SUFFIXES was already cleared.) (bug#64743)
+ - GNU Make's default pattern rules for RCS and SCCS are disabled, for
+ speed and debugging. (.SUFFIXES was already cleared.) (bug#64743)
- For Texinfo documents, if a .texi.in file exists, but no .texi, the
.texi.in will be read. Texinfo source files need not be present at
diff --git a/lib/py-compile b/lib/py-compile
index 9659beca6..0cfddedb6 100755
--- a/lib/py-compile
+++ b/lib/py-compile
@@ -33,6 +33,23 @@ fi
me=py-compile
+# People apparently set PYTHON=: and expect the result to be true.
+# For the same reason, we output to stdout instead of stderr. Bizarre.
+if $PYTHON -V 2>/dev/null | grep -i python >/dev/null; then :; else
+ echo "$me: Invalid python executable (according to -V): $PYTHON"
+ echo "$me: Python support disabled"
+ if test x"$PYTHON" = xfalse; then
+ # But, as a special case, make PYTHON=false exit unsuccessfully,
+ # since that was the traditional behavior.
+ exit 1
+ # In the past, setting PYTHON to any command that exited unsuccessfully
+ # caused py-compile to exit unsuccessfully. Let's not try to
+ # replicate that unless and until needed.
+ else
+ exit 0
+ fi
+fi
+
usage_error ()
{
echo "$me: $*" >&2
@@ -64,7 +81,7 @@ while test $# -ne 0; do
cat <<\EOF
Usage: py-compile [options] FILES...
-Byte compile some python scripts FILES. Use --destdir to specify any
+Byte compile FILES as Python scripts. Use --destdir to specify a
leading directory path to the FILES that you don't want to include in the
byte compiled file. Specify --basedir for any additional path information you
do want to be shown in the byte compiled file.
@@ -78,6 +95,14 @@ Options:
Example:
py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
+The Python interpreter to use is taken from the environment variable
+PYTHON, or "python" by default.
+
+For compatibility: as a special case, if PYTHON=false (that is, the
+command named "false"), this script will exit unsuccessfully. Otherwise,
+if $PYTHON -V does not include the string "Python", this script will
+emit a message to standard output and exit successfully.
+
Report bugs to <bug-automake <at> gnu.org>.
GNU Automake home page: <https://www.gnu.org/software/automake/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
diff --git a/t/py-compile-env.sh b/t/py-compile-env.sh
index 564fb98c6..3411ddd5d 100644
--- a/t/py-compile-env.sh
+++ b/t/py-compile-env.sh
@@ -31,9 +31,15 @@ chmod a+x my-py
mkdir sub1
cd sub1
+# This py-compile invocation should succeed and do nothing.
+PYTHON=: ../py-compile foo.py
+ls | grep . && exit 1
+
+# This py-compile invocation should fail and do nothing.
PYTHON=false ../py-compile foo.py && exit 1
ls | grep . && exit 1
+# These should also do nothing, and succeed.
PYTHON='echo GrEpMe AndMeToo' ../py-compile foo.py
PYTHON='echo GrEpMe AndMeToo' ../py-compile foo.py | grep 'GrEpMe AndMeToo'
ls | grep . && exit 1
compile finished at Sun Feb 9 09:36:24 2025
This bug report was last modified 161 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.