From c7a9537dba900cae8e10c2bb191543544b555ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 8 Dec 2021 14:35:51 +0000 Subject: [PATCH] Set %__python3 value according to %python3_pkgversion I.e. when %python3_pkgversion is 3.12, %__python3 is /usr/bin/python3.12 We assume that when packagers package for Python 3.X, they want to change both %python3_pkgversion and %__python3 value. Hence instead of copy-pasting this: %global python3_pkgversion 3.X %global __python3 /usr/bin/python3.X They just need to do: %global python3_pkgversion 3.X Packagers who want to change the value of %__python3 without touching %python3_pkgversion can still do it: %global __python3 /usr/bin/pypy3 Related: rhbz#1950291 --- macros.python-srpm | 2 +- python-rpm-macros.spec | 6 +++++- tests/test_evals.py | 19 +++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/macros.python-srpm b/macros.python-srpm index cf9682c..b30a6c8 100644 --- a/macros.python-srpm +++ b/macros.python-srpm @@ -37,7 +37,7 @@ # use the underscored macros to redefine the behavior of %%python3_version etc. %__python2 /usr/bin/python2 -%__python3 /usr/bin/python3 +%__python3 /usr/bin/python%{python3_pkgversion} # use the non-underscored macros to refer to Python in spec, etc. %python2 %__python2 diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index fc07406..b923d6d 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3.9 -Release: 46%{?dist} +Release: 47%{?dist} Summary: The common Python RPM macros URL: https://src.fedoraproject.org/rpms/python-rpm-macros/ @@ -101,6 +101,10 @@ install -m 644 import_all_modules.py %{buildroot}%{_rpmconfigdir}/redhat/ %changelog +* Wed Dec 08 2021 Miro HronĨok - 3.9-47 +- Set %%__python3 value according to %%python3_pkgversion + I.e. when %%python3_pkgversion is 3.12, %%__python3 is /usr/bin/python3.12 + * Mon Nov 01 2021 Karolina Surma - 3.9-46 - Fix multiline arguments processing for %%py_check_import - Fix %%py_shebang_flags handling within %%py_check_import diff --git a/tests/test_evals.py b/tests/test_evals.py index 861dc35..64b1b65 100644 --- a/tests/test_evals.py +++ b/tests/test_evals.py @@ -83,6 +83,17 @@ def shell_stdout(script): shell=True).rstrip() +@pytest.mark.parametrize('macro', ['%__python3', '%python3']) +def test_python3(macro): + assert rpm_eval(macro) == ['/usr/bin/python3'] + + +@pytest.mark.parametrize('macro', ['%__python3', '%python3']) +@pytest.mark.parametrize('pkgversion', ['3', '3.9', '3.12']) +def test_python3_with_pkgversion(macro, pkgversion): + assert rpm_eval(macro, python3_pkgversion=pkgversion) == [f'/usr/bin/python{pkgversion}'] + + @pytest.mark.parametrize('argument, result', [ ('a', 'a'), ('a-a', 'a-a'), @@ -629,7 +640,9 @@ def test_python3_sitelib_value_default(): def test_python3_sitelib_value_alternate_python(alt_x_y): macro = '%python3_sitelib' - assert rpm_eval(macro, __python3=f'/usr/bin/python{alt_x_y}') == [f'/usr/lib/python{alt_x_y}/site-packages'] + assert (rpm_eval(macro, __python3=f'/usr/bin/python{alt_x_y}') == + rpm_eval(macro, python3_pkgversion=alt_x_y) == + [f'/usr/lib/python{alt_x_y}/site-packages']) def test_python_sitearch_value_python3(lib): @@ -649,7 +662,9 @@ def test_python3_sitearch_value_default(lib): def test_python3_sitearch_value_alternate_python(lib, alt_x_y): macro = '%python3_sitearch' - assert rpm_eval(macro, __python3=f'/usr/bin/python{alt_x_y}') == [f'/usr/{lib}/python{alt_x_y}/site-packages'] + assert (rpm_eval(macro, __python3=f'/usr/bin/python{alt_x_y}') == + rpm_eval(macro, python3_pkgversion=alt_x_y) == + [f'/usr/{lib}/python{alt_x_y}/site-packages']) @pytest.mark.parametrize(