]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
py-compile: drop support for Python 0.x & 1.x
authorMike Frysinger <vapier@gentoo.org>
Sun, 6 Feb 2022 05:22:50 +0000 (00:22 -0500)
committerMike Frysinger <vapier@gentoo.org>
Sun, 6 Feb 2022 05:22:50 +0000 (00:22 -0500)
Python 2.0 was released in 2000.  There's really no way for us to check
those old versions, so let's just drop them.  No one will miss them.

* NEWS: Note Python version support removal.
* lib/py-compile: Abort if major version 0 or 1 is found.
* t/py-compile-env.sh: Rework slightly to handle new version probing.

NEWS
lib/py-compile
t/py-compile-env.sh

diff --git a/NEWS b/NEWS
index f408605077078768b5f12ada78f6c39001a1239c..29c4d8a9658866738604efbba227070dc2ad3e0e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,11 @@ New in 1.17:
 
   - AM_TEXI2FLAGS may be defined to pass extra flags to TEXI2DVI & TEXI2PDF.
 
+* Obsolescent features:
+
+  - py-compile no longer supports Python 0.x or 1.x versions.  Python 2.0,
+    released in 2000, is currently the minimum required version.
+
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 New in 1.16.5:
index ccf40623540623270441e255ca1b147942dec9e3..734bd6a3cd7f38c622b585a30ebd697ab0b04a5b 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # py-compile - Compile a Python program
 
-scriptversion=2022-02-06.05; # UTC
+scriptversion=2022-02-06.06; # UTC
 
 # Copyright (C) 2000-2022 Free Software Foundation, Inc.
 
@@ -120,27 +120,19 @@ else
   filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
 fi
 
-python_major=`$PYTHON -V 2>&1 | sed -e 's/.* //;s/\..*$//;1q'`
+python_major=`$PYTHON -c 'import sys; print(sys.version_info[0])'`
 if test -z "$python_major"; then
-  echo "$me: could not determine $PYTHON major version, guessing 3" >&2
-  python_major=3
+  usage_error "could not determine $PYTHON major version"
 fi
 
-# The old way to import libraries was deprecated.
-if test "$python_major" -le 2; then
-  import_lib=imp
-  import_test="hasattr(imp, 'get_tag')"
-  import_call=imp.cache_from_source
-  import_arg2=', False' # needed in one call and not the other
-else
-  import_lib=importlib
-  import_test="hasattr(sys.implementation, 'cache_tag')"
-  import_call=importlib.util.cache_from_source
-  import_arg2=
-fi
+case $python_major in
+[01])
+  usage_error "python version 0.x and 1.x not supported"
+  ;;
+esac
 
 $PYTHON -c "
-import sys, os, py_compile, $import_lib
+import sys, os, py_compile, importlib
 
 sys.stdout.write('Byte-compiling python modules...\n')
 for file in sys.argv[1:]:
@@ -151,15 +143,14 @@ for file in sys.argv[1:]:
            continue
     sys.stdout.write(file)
     sys.stdout.flush()
-    if $import_test:
-        py_compile.compile(filepath, $import_call(filepath), path)
+    if hasattr(sys.implementation, 'cache_tag'):
+        py_compile.compile(filepath, importlib.util.cache_from_source(filepath), path)
     else:
         py_compile.compile(filepath, filepath + 'c', path)
 sys.stdout.write('\n')" "$@" || exit $?
 
-# this will fail for python < 1.5, but that doesn't matter ...
 $PYTHON -O -c "
-import sys, os, py_compile, $import_lib
+import sys, os, py_compile, importlib
 
 # pypy does not use .pyo optimization
 if hasattr(sys, 'pypy_translation_info'):
@@ -174,8 +165,8 @@ for file in sys.argv[1:]:
            continue
     sys.stdout.write(file)
     sys.stdout.flush()
-    if $import_test:
-        py_compile.compile(filepath, $import_call(filepath$import_arg2), path)
+    if hasattr(sys.implementation, 'cache_tag'):
+        py_compile.compile(filepath, importlib.util.cache_from_source(filepath), path)
     else:
         py_compile.compile(filepath, filepath + 'o', path)
 sys.stdout.write('\n')" "$@" 2>/dev/null || exit $?
index 2c7fe508488aac921fbc6cb80e6395284a1b0500..e7998589278e9b34fb9d0adcc2088b0a12394826 100644 (file)
@@ -23,6 +23,7 @@ cp "$am_scriptdir/py-compile" . \
 
 cat > my-py <<'END'
 #!/bin/sh
+echo 2
 : > my-py.run
 END
 chmod a+x my-py
@@ -30,9 +31,6 @@ chmod a+x my-py
 mkdir sub1
 cd sub1
 
-PYTHON=: ../py-compile foo.py
-ls | grep . && exit 1
-
 PYTHON=false ../py-compile foo.py && exit 1
 ls | grep . && exit 1