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
This commit is contained in:
Miro Hrončok 2021-12-08 14:35:51 +00:00
parent 3a652b1c29
commit c7a9537dba
3 changed files with 23 additions and 4 deletions

View File

@ -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

View File

@ -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 <mhroncok@redhat.com> - 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 <ksurma@redhat.com> - 3.9-46
- Fix multiline arguments processing for %%py_check_import
- Fix %%py_shebang_flags handling within %%py_check_import

View File

@ -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(