summaryrefslogtreecommitdiff
path: root/proto/xcb-proto/py-compile
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2022-07-17 08:19:04 +0000
committerMatthieu Herrb <matthieu@cvs.openbsd.org>2022-07-17 08:19:04 +0000
commit6b0010bc7622d889f9f972dfd97582c267b5b1aa (patch)
tree053201f40fc29a8a3ec5167f968691cdb8082154 /proto/xcb-proto/py-compile
parent71c2e9f9153cbc5d3a7d8ce5737fdd69d95ee55a (diff)
Update xcb-protos to 1.15.2
Diffstat (limited to 'proto/xcb-proto/py-compile')
-rw-r--r--proto/xcb-proto/py-compile74
1 files changed, 57 insertions, 17 deletions
diff --git a/proto/xcb-proto/py-compile b/proto/xcb-proto/py-compile
index 9f8baf7ab..5a8e4e3d9 100644
--- a/proto/xcb-proto/py-compile
+++ b/proto/xcb-proto/py-compile
@@ -1,9 +1,9 @@
#!/bin/sh
# py-compile - Compile a Python program
-scriptversion=2018-03-07.03; # UTC
+scriptversion=2021-02-27.01; # UTC
-# Copyright (C) 2000-2018 Free Software Foundation, Inc.
+# Copyright (C) 2000-2021 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@ scriptversion=2018-03-07.03; # UTC
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
-if [ -z "$PYTHON" ]; then
+if test -z "$PYTHON"; then
PYTHON=python
fi
@@ -96,27 +96,44 @@ done
files=$*
if test -z "$files"; then
- usage_error "no files given"
+ usage_error "no files given"
fi
# if basedir was given, then it should be prepended to filenames before
# byte compilation.
-if [ -z "$basedir" ]; then
- pathtrans="path = file"
+if test -z "$basedir"; then
+ pathtrans="path = file"
else
- pathtrans="path = os.path.join('$basedir', file)"
+ pathtrans="path = os.path.join('$basedir', file)"
fi
# if destdir was given, then it needs to be prepended to the filename to
# byte compile but not go into the compiled file.
-if [ -z "$destdir" ]; then
- filetrans="filepath = path"
+if test -z "$destdir"; then
+ filetrans="filepath = path"
else
- filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
+ 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
+else
+ import_lib=importlib
+ import_test="hasattr(sys.implementation, 'cache_tag')"
+ import_call=importlib.util.cache_from_source
fi
$PYTHON -c "
-import sys, os, py_compile, imp
+import sys, os, py_compile, $import_lib
files = '''$files'''
@@ -129,18 +146,18 @@ 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'):
+if hasattr(sys, 'pypy_translation_info') and sys.hexversion < 0x03050000:
sys.exit(0)
files = '''$files'''
@@ -153,12 +170,35 @@ 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), path)
else:
py_compile.compile(filepath, filepath + 'o', path)
sys.stdout.write('\n')" 2>/dev/null || :
+$PYTHON -OO -c "
+import sys, os, py_compile, $import_lib
+
+# python<3.5 does not have split files for -O and -OO
+if sys.hexversion < 0x03050000:
+ sys.exit(0)
+
+files = '''$files'''
+sys.stdout.write('Byte-compiling python modules (optimized versions) ...\n')
+for file in files.split():
+ $pathtrans
+ $filetrans
+ if not os.path.exists(filepath) or not (len(filepath) >= 3
+ and filepath[-3:] == '.py'):
+ continue
+ sys.stdout.write(file)
+ sys.stdout.flush()
+ if $import_test:
+ py_compile.compile(filepath, $import_call(filepath), path)
+ else:
+ py_compile.compile(filepath, filepath + 'o', path)
+sys.stdout.write('\n')" 2>/dev/null || exit $?
+
# Local Variables:
# mode: shell-script
# sh-indentation: 2