mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2026-02-16 05:11:59 +01:00
91 lines
2.8 KiB
Diff
91 lines
2.8 KiB
Diff
From 9ba2f0ddbcf08d4d67baffa8779abff7042a1c96 Mon Sep 17 00:00:00 2001
|
|
From: Karl Berry <karl@freefriends.org>
|
|
Date: Tue, 25 Feb 2020 18:07:15 -0800
|
|
Subject: python: support both Python 2 and 3 in py-compile
|
|
|
|
* lib/py-compile: check python major version and use imp
|
|
or importlib accordingly, plus related changes. Original
|
|
patch for Python 3 only from Gabriel Ganne at:
|
|
https://lists.gnu.org/archive/html/automake-patches/2019-07/msg00002.html
|
|
---
|
|
lib/py-compile | 33 ++++++++++++++++++++++++++-------
|
|
1 file changed, 26 insertions(+), 7 deletions(-)
|
|
|
|
(limited to 'lib/py-compile')
|
|
|
|
diff --git a/lib/py-compile b/lib/py-compile
|
|
index f2be7d0..e56d98d 100755
|
|
--- a/py-compile
|
|
+++ b/py-compile
|
|
@@ -1,7 +1,7 @@
|
|
#!/bin/sh
|
|
# py-compile - Compile a Python program
|
|
|
|
-scriptversion=2018-03-07.03; # UTC
|
|
+scriptversion=2020-02-19.23; # UTC
|
|
|
|
# Copyright (C) 2000-2020 Free Software Foundation, Inc.
|
|
|
|
@@ -115,8 +115,27 @@ else
|
|
filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
|
|
fi
|
|
|
|
+python_major=$($PYTHON -V 2>&1 | sed -e 's/.* //;s/\..*$//;1q')
|
|
+if test -z "$python_major"; then
|
|
+ echo "$me: could not determine $PYTHON major version, guessing 3" >&2
|
|
+ python_major=3
|
|
+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
|
|
+
|
|
$PYTHON -c "
|
|
-import sys, os, py_compile, imp
|
|
+import sys, os, py_compile, $import_lib
|
|
|
|
files = '''$files'''
|
|
|
|
@@ -129,15 +148,15 @@ for file in files.split():
|
|
continue
|
|
sys.stdout.write(file)
|
|
sys.stdout.flush()
|
|
- if hasattr(imp, 'get_tag'):
|
|
- py_compile.compile(filepath, imp.cache_from_source(filepath), path)
|
|
+ if $import_test:
|
|
+ py_compile.compile(filepath, $import_call(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, imp
|
|
+import sys, os, py_compile, $import_lib
|
|
|
|
# pypy does not use .pyo optimization
|
|
if hasattr(sys, 'pypy_translation_info'):
|
|
@@ -153,8 +172,8 @@ for file in files.split():
|
|
continue
|
|
sys.stdout.write(file)
|
|
sys.stdout.flush()
|
|
- if hasattr(imp, 'get_tag'):
|
|
- py_compile.compile(filepath, imp.cache_from_source(filepath, False), path)
|
|
+ if $import_test:
|
|
+ py_compile.compile(filepath, $import_call(filepath$import_arg2), path)
|
|
else:
|
|
py_compile.compile(filepath, filepath + 'o', path)
|
|
sys.stdout.write('\n')" 2>/dev/null || :
|
|
--
|
|
cgit v1.1
|
|
|