]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
macros: Replace macro to compile Python modules
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 8 Nov 2022 18:26:50 +0000 (18:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 8 Nov 2022 18:26:50 +0000 (18:26 +0000)
This also drops compiling modules for Python2

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
macros/build.macro
src/scripts/py-compile [deleted file]

index da8ac0e85f867a02d4cc3d7810f6f7bf0ecd579d..452ec7ad7d1815ce9d58c6821b1266652e1f213c 100644 (file)
@@ -709,7 +709,6 @@ dist_scripts_SCRIPTS = \
        src/scripts/find-requires \
        src/scripts/perl.prov \
        src/scripts/perl.req \
-       src/scripts/py-compile \
        src/scripts/remove-static-libs \
        src/scripts/strip
 
index dc79cc9ade303361d6cdbd5988dedb3b252dcab7..dafc1d601efa5c1c3e0793bb7b98771ae1c56ee9 100644 (file)
@@ -46,17 +46,15 @@ def MACRO_INSTALL_LOGROTATE_FILES
 end
 
 def MACRO_PYTHON_COMPILE
-       if [ -x "%{python3}" ]; then
-               %{python3_bytecompile} \
-                       %{BUILDROOT}%{python3_sitearch} \
-                       %{BUILDROOT}%{python3_sitelib}
-       fi
+       __python_compile() {
+               if [ -x "%{python3}" ]; then
+                       %{python3} -m compileall -f \
+                               %{BUILDROOT}%{python3_sitearch} %{BUILDROOT}%{python3_sitelib} $@
+               fi
+       }
 
-       if [ -x "%{python}" ]; then
-               %{python_bytecompile} \
-                       %{BUILDROOT}%{python_sitearch} \
-                       %{BUILDROOT}%{python_sitelib}
-       fi
+       # Compile any Python modules
+       __python_compile
 end
 
 def MACRO_FIX_AUTOTOOLS
diff --git a/src/scripts/py-compile b/src/scripts/py-compile
deleted file mode 100644 (file)
index 2749042..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/bin/sh
-
-python_interpreter="python"
-paths=""
-
-while [ $# -gt 0 ]; do
-       case "${1}" in
-               --python=*)
-                       python_interpreter=${1#--python=}
-                       ;;
-               *)
-                       paths="${paths} ${1}"
-                       ;;
-       esac
-       shift
-done
-
-if [ -z "${paths}" ]; then
-       echo >&2 "No path specified!"
-       exit 1
-fi
-
-if [ "${python_interpreter:0:1}" != "/" ]; then
-       python_interpreter=$(which ${python_interpreter} 2>/dev/null)
-fi
-
-if [ ! -x "${python_interpreter}" ]; then
-       echo >&2 "Python interpreter is not executable: ${python_interpreter}"
-       exit 1
-fi
-
-tempfile=$(mktemp)
-trap "rm -f ${tempfile}" EXIT
-
-cat > ${tempfile} <<EOF
-import os
-import py_compile
-import sys
-
-for file in sys.argv[1:]:
-       if not os.path.exists(file):
-               continue
-
-       py_compile.compile(file, doraise=0)
-EOF
-
-filelist=$(find ${paths} -type f -a -name "*.py" 2>/dev/null)
-
-# Compile with optimization.
-${python_interpreter} -O ${tempfile} ${filelist}
-
-# Compile without optimization.
-${python_interpreter} ${tempfile} ${filelist}
-
-# Hardlink identical files.
-for pyc in $(find ${paths} -type f -a -name "*.pyc" 2>/dev/null); do
-       pyo="${pyc/.pyc/.pyo}"
-
-       if cmp -s "${pyc}" "${pyo}"; then
-               ln -f "${pyc}" "${pyo}"
-       fi
-done