From ead8ec025b7f6f534ff1d2c07e64bf3b7fe876be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 20 May 2020 13:13:22 +0200 Subject: [PATCH] Backport simplified %py_provides This is a smallest possible backport of https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/52 Notable simplifications: - there is no Lua library - %python_provide remains untouched and the logic is not shared with %py_provides - there are no pythonXY-foo provides on Fedora < 33 --- macros.python-srpm | 17 +++++++++ python-rpm-macros.spec | 5 ++- tests/.gitignore | 1 + tests/test_evals.py | 83 ++++++++++++++++++++++++++++++++++++++++++ tests/tests.yml | 22 +++++++++++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 tests/.gitignore create mode 100644 tests/test_evals.py create mode 100644 tests/tests.yml diff --git a/macros.python-srpm b/macros.python-srpm index 9fa4f06..a1b75d6 100644 --- a/macros.python-srpm +++ b/macros.python-srpm @@ -132,3 +132,20 @@ \ print(url .. first .. '/' .. src .. '/' .. src .. '-' .. ver .. '.' .. ext) } + +%py_provides() %{lua: + local name = rpm.expand('%1') + if name == '%1' then + rpm.expand('%{error:%%py_provides requires at least 1 argument, the name to provide}') + end + local evr = rpm.expand('%2') + if evr == '%2' then + evr = rpm.expand('%{?epoch:%{epoch}:}%{version}-%{release}') + end + print('Provides: ' .. name .. ' = ' .. evr .. '\\n') + -- NB: dash needs to be escaped! + if name:match('^python3%-') then + replaced = name:gsub('^python3%-', 'python-') + print('Provides: ' .. replaced .. ' = ' .. evr .. '\\n') + end +} diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index 8a4637b..239c390 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3 -Release: 55%{?dist} +Release: 56%{?dist} Summary: The unversioned Python RPM macros # macros: MIT, compileall2.py: PSFv2 @@ -80,6 +80,9 @@ install -m 644 %{SOURCE5} \ %changelog +* Wed May 20 2020 Miro Hrončok - 3-56 +- Implement %%py_provides + * Tue Apr 28 2020 Miro Hrončok - 3-55 - Make pythonX-rpm-macros depend on python-rpm-macros (#1827811) diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..5732c0f --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +__*__/ diff --git a/tests/test_evals.py b/tests/test_evals.py new file mode 100644 index 0000000..8547c73 --- /dev/null +++ b/tests/test_evals.py @@ -0,0 +1,83 @@ +import subprocess +import sys + + +def rpm_eval(expression, **kwargs): + cmd = ['rpmbuild'] + for var, value in kwargs.items(): + cmd += ['--define', f'{var} {value}'] + cmd += ['--eval', expression] + cp = subprocess.run(cmd, text=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + assert cp.returncode == 0, cp.stderr + return cp.stdout.strip().splitlines() + + +def test_python_provide_python(): + assert rpm_eval('%python_provide python-foo') == [] + + +def test_python_provide_python3(): + lines = rpm_eval('%python_provide python3-foo', version='6', release='1.fc66') + assert 'Obsoletes: python-foo < 6-1.fc66' in lines + assert 'Provides: python-foo = 6-1.fc66' in lines + assert len(lines) == 2 + + +def test_python_provide_python3_epoched(): + lines = rpm_eval('%python_provide python3-foo', epoch='1', version='6', release='1.fc66') + assert 'Obsoletes: python-foo < 1:6-1.fc66' in lines + assert 'Provides: python-foo = 1:6-1.fc66' in lines + assert len(lines) == 2 + + +def test_python_provide_doubleuse(): + lines = rpm_eval('%{python_provide python3-foo}%{python_provide python3-foo}', + version='6', release='1.fc66') + assert 'Obsoletes: python-foo < 6-1.fc66' in lines + assert 'Provides: python-foo = 6-1.fc66' in lines + assert len(lines) == 4 + assert len(set(lines)) == 2 + + +def test_py_provides_python(): + lines = rpm_eval('%py_provides python-foo', version='6', release='1.fc66') + assert 'Provides: python-foo = 6-1.fc66' in lines + assert len(lines) == 1 + + +def test_py_provides_whatever(): + lines = rpm_eval('%py_provides whatever', version='6', release='1.fc66') + assert 'Provides: whatever = 6-1.fc66' in lines + assert len(lines) == 1 + + +def test_py_provides_python3(): + lines = rpm_eval('%py_provides python3-foo', version='6', release='1.fc66') + assert 'Provides: python3-foo = 6-1.fc66' in lines + assert 'Provides: python-foo = 6-1.fc66' in lines + assert len(lines) == 2 + + +def test_py_provides_python3_epoched(): + lines = rpm_eval('%py_provides python3-foo', epoch='1', version='6', release='1.fc66') + assert 'Provides: python3-foo = 1:6-1.fc66' in lines + assert 'Provides: python-foo = 1:6-1.fc66' in lines + assert len(lines) == 2 + + +def test_py_provides_doubleuse(): + lines = rpm_eval('%{py_provides python3-foo}%{py_provides python3-foo}', + version='6', release='1.fc66') + assert 'Provides: python3-foo = 6-1.fc66' in lines + assert 'Provides: python-foo = 6-1.fc66' in lines + assert len(lines) == 4 + assert len(set(lines)) == 2 + + +def test_py_provides_with_evr(): + lines = rpm_eval('%py_provides python3-foo 123', + version='6', release='1.fc66') + assert 'Provides: python3-foo = 123' in lines + assert 'Provides: python-foo = 123' in lines + assert len(lines) == 2 diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..56221e3 --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,22 @@ +--- +- hosts: localhost + tags: + - classic + tasks: + - dnf: + name: "*" + state: latest + +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - classic + tests: + - pytest: + dir: . + run: pytest -v + required_packages: + - rpm-build + - python-rpm-macros + - python3-pytest