From b7c8579cc2eb8ca33260dabfb10a18ea4b53243d Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 8 Nov 2022 18:26:50 +0000 Subject: [PATCH] macros: Replace macro to compile Python modules This also drops compiling modules for Python2 Signed-off-by: Michael Tremer --- Makefile.am | 1 - macros/build.macro | 18 ++++++------ src/scripts/py-compile | 62 ------------------------------------------ 3 files changed, 8 insertions(+), 73 deletions(-) delete mode 100644 src/scripts/py-compile diff --git a/Makefile.am b/Makefile.am index da8ac0e8..452ec7ad 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/macros/build.macro b/macros/build.macro index dc79cc9a..dafc1d60 100644 --- a/macros/build.macro +++ b/macros/build.macro @@ -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 index 27490426..00000000 --- a/src/scripts/py-compile +++ /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} </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 -- 2.39.2