From b55e6151bd54255378d0beaaf6107d3fe99ce56a Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: Dec 08 2021 13:37:09 +0000 Subject: [PATCH 1/2] Move %python3_pkgversion definition earlier in the file So we can use it later in %__python3 and maintain readability. --- diff --git a/macros.python-srpm b/macros.python-srpm index dcc7023..fcffd23 100644 --- a/macros.python-srpm +++ b/macros.python-srpm @@ -1,22 +1,3 @@ -# Define the Python interpreter paths in the SRPM macros so that -# - they can be used in Build/Requires -# - they can be used in non-Python packages where requiring pythonX-devel would -# be an overkill - -# use the underscored macros to redefine the behavior of %%python3_version etc. -%__python2 /usr/bin/python2 -%__python3 /usr/bin/python3 - -# use the non-underscored macros to refer to Python in spec, etc. -%python2 %__python2 -%python3 %__python3 - -# See https://fedoraproject.org/wiki/Changes/PythonMacroError -%__python %{error:attempt to use unversioned python, define %%__python to %{__python2} or %{__python3} explicitly} - -# Users can use %%python only if they redefined %%__python (e.g. to %%__python3) -%python %__python - # There are multiple Python 3 versions packaged, but only one can be the "main" version # That means that it owns the "python3" namespace: # - python3 package name @@ -49,6 +30,25 @@ # Alternatively, it can be overridden in spec (e.g. to "3.8") when building for alternate Python stacks. %python3_pkgversion 3 +# Define the Python interpreter paths in the SRPM macros so that +# - they can be used in Build/Requires +# - they can be used in non-Python packages where requiring pythonX-devel would +# be an overkill + +# use the underscored macros to redefine the behavior of %%python3_version etc. +%__python2 /usr/bin/python2 +%__python3 /usr/bin/python3 + +# use the non-underscored macros to refer to Python in spec, etc. +%python2 %__python2 +%python3 %__python3 + +# See https://fedoraproject.org/wiki/Changes/PythonMacroError +%__python %{error:attempt to use unversioned python, define %%__python to %{__python2} or %{__python3} explicitly} + +# Users can use %%python only if they redefined %%__python (e.g. to %%__python3) +%python %__python + # Define where Python wheels will be stored and the prefix of -wheel packages # - In Fedora we want wheel subpackages named e.g. `python-pip-wheel` that # install packages into `/usr/share/python-wheels`. Both names are not From a8b26546eb699afe0dbfcef913a2aa7085fc5afb Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: Dec 08 2021 14:35:51 +0000 Subject: [PATCH 2/2] 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 pacakge 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 to https://bugzilla.redhat.com/1821489 --- diff --git a/macros.python-srpm b/macros.python-srpm index fcffd23..3009f3f 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 0f68adc..3483cac 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -49,7 +49,7 @@ elseif posix.stat('macros.python-srpm') then end } Version: %{__default_python3_version} -Release: 13%{?dist} +Release: 14%{?dist} BuildArch: noarch @@ -145,6 +145,10 @@ install -m 755 brp-* %{buildroot}%{_rpmconfigdir}/redhat/ %changelog +* Wed Dec 08 2021 Miro Hrončok - 3.10-14 +- 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.10-13 - Fix multiline arguments processing for %%py_check_import Resolves: rhbz#2018809 diff --git a/tests/test_evals.py b/tests/test_evals.py index 6a771ed..ae2b606 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'), @@ -647,7 +658,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): @@ -667,7 +680,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(