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
This commit is contained in:
Miro Hrončok 2021-12-08 12:16:03 +01:00
parent b55e6151bd
commit a8b26546eb
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

@ -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 <mhroncok@redhat.com> - 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 <ksurma@redhat.com> - 3.10-13
- Fix multiline arguments processing for %%py_check_import
Resolves: rhbz#2018809

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'),
@ -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(