[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#38043: [PATCH 4/6] py-compile: drop support for Python 0.x & 1.x
From: |
Mike Frysinger |
Subject: |
bug#38043: [PATCH 4/6] py-compile: drop support for Python 0.x & 1.x |
Date: |
Sun, 6 Feb 2022 01:57:12 -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.
* lib/py-compile: Abort if major version 0 or 1 is found.
* t/py-compile-env.sh: Rework slightly to handle new version probing.
---
lib/py-compile | 35 +++++++++++++----------------------
t/py-compile-env.sh | 4 +---
2 files changed, 14 insertions(+), 25 deletions(-)
diff --git a/lib/py-compile b/lib/py-compile
index 0e1df24024e8..2745d0b6b045 100755
--- a/lib/py-compile
+++ b/lib/py-compile
@@ -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 $?
diff --git a/t/py-compile-env.sh b/t/py-compile-env.sh
index 2c7fe508488a..e7998589278e 100644
--- a/t/py-compile-env.sh
+++ b/t/py-compile-env.sh
@@ -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
--
2.34.1