File 151.patch of Package python-rpm-macros

From 7148831191574b86763aebc6215325038a983457 Mon Sep 17 00:00:00 2001
From: Ben Greiner <code@bnavigator.de>
Date: Sat, 28 Jan 2023 11:18:20 +0100
Subject: [PATCH 1/2] Strip buildroot from pyc files: Use py_compile instead of
 compileall deduplicate code: make %{python_compileall} call new
 %{$python_compile}

---
 flavor.in              |  7 +++++--
 macros.lua             |  7 +++++++
 macros/010-common-defs | 13 -------------
 3 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/flavor.in b/flavor.in
index ab51047..ecae95d 100644
--- a/flavor.in
+++ b/flavor.in
@@ -81,11 +81,14 @@ if [ $havereq -eq 0 ]; then \
   done \
 fi \
 %__#FLAVOR# -mpip install %{pyproject_install_args} $myargs \
+%#FLAVOR#_compile
+
+%#FLAVOR#_compile \
 for d in %{buildroot}%{#FLAVOR#_sitelib} %{buildroot}%{#FLAVOR#_sitearch}; do \
   if [ -d $d ]; then \
     find $d -name '*.pyc' -delete \
-    %__#FLAVOR# -m compileall $d \
-    %__#FLAVOR# -O -m compileall $d \
+    find $d -iname '*.py' -exec %__#FLAVOR# -c \\\
+       'import py_compile; f="{}"; [py_compile.compile(f, dfile=f[len("%{buildroot}"):], optimize=o) for o in [0, 1]]' ';' \
   fi \
 done
 
diff --git a/macros.lua b/macros.lua
index 486a227..9c8f54d 100644
--- a/macros.lua
+++ b/macros.lua
@@ -460,6 +460,13 @@ function pyproject_install(+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
     end
 end
 
+function python_compileall()
+    rpm.expand("%_python_macro_init")
+    for _, python in ipairs(pythons) do
+        print(rpm.expand("%" .. python .. "_compile"))
+    end
+end
+
 function python_files()
     rpm.expand("%_python_macro_init")
     local nparams = rpm.expand("%#")
diff --git a/macros/010-common-defs b/macros/010-common-defs
index 8d83ee5..72da64b 100644
--- a/macros/010-common-defs
+++ b/macros/010-common-defs
@@ -170,19 +170,6 @@
     print(rpm.expand(intro .. args .. "}")) \
 }
 
-##### Precompile scripts macro #####
-
-%python_compileall \
-%{python_expand for d in %{buildroot}%{$python_sitelib} %{buildroot}%{$python_sitearch}; do \
-  if [ -d $d ]; then \
-    find $d -name '*.pyc' -delete; \
-    $python -m compileall $d; \
-    $python -O -m compileall $d; \
-  fi; \
-done \
-} \
-%{nil}
-
 ##### Find language files #####
 
 %python_find_lang() \

From e7bd1050b89fe1484a6e4ac7adc42bb67384d675 Mon Sep 17 00:00:00 2001
From: Ben Greiner <code@bnavigator.de>
Date: Sat, 28 Jan 2023 16:57:08 +0100
Subject: [PATCH 2/2] python_compile: Add output message

---
 flavor.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flavor.in b/flavor.in
index ecae95d..a9a43f6 100644
--- a/flavor.in
+++ b/flavor.in
@@ -86,8 +86,8 @@ fi \
 %#FLAVOR#_compile \
 for d in %{buildroot}%{#FLAVOR#_sitelib} %{buildroot}%{#FLAVOR#_sitearch}; do \
   if [ -d $d ]; then \
-    find $d -name '*.pyc' -delete \
-    find $d -iname '*.py' -exec %__#FLAVOR# -c \\\
+    find $d -iname '*.pyc' -delete \
+    find $d -iname '*.py' -printf 'Generating cached byte-code for %%P\\n' -exec %__#FLAVOR# -c \\\
        'import py_compile; f="{}"; [py_compile.compile(f, dfile=f[len("%{buildroot}"):], optimize=o) for o in [0, 1]]' ';' \
   fi \
 done
openSUSE Build Service is sponsored by