#!/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.
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:]:
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'):
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 $?