From ca0a3311c552bd71485c3193b88e950aa1d1a533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 7 Apr 2021 10:48:38 +0000 Subject: [PATCH] Allow commas as argument separator for extras names in %python_extras_subpkg This allows e.g.: %global extras cli,ghostwriter,pytz,dateutil,lark,numpy,pandas,pytest,redis,zoneinfo,django %{pyproject_extras_subpkg -n python3-hypothesis %{extras}} ... %pyproject_buildrequires -x %{extras} (Note that %pyproject_extras_subpkg is a tiny wrapper around %python_extras_subpkg.) Related: rhbz#1950291 --- macros.python-srpm | 2 +- python-rpm-macros.spec | 6 +++++- tests/test_evals.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/macros.python-srpm b/macros.python-srpm index 996b0f9..efe2bba 100644 --- a/macros.python-srpm +++ b/macros.python-srpm @@ -198,7 +198,7 @@ rpm.expand('%{error:%%%0 requires at least one argument with "extras" name}') end local requires = 'Requires: ' .. value_n .. ' = %{?epoch:%{epoch}:}%{version}-%{release}' - for extras in args:gmatch('%S+') do + for extras in args:gmatch('[^%s,]+') do local rpmname = value_n .. '+' .. extras local pkgdef = '%package -n ' .. rpmname local summary = 'Summary: Metapackage for ' .. value_n .. ': ' .. extras .. ' extras' diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index e2b9f8b..3fbb6ad 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3.9 -Release: 36%{?dist} +Release: 36.1%{?dist} Summary: The common Python RPM macros # macros and lua: MIT, compileall2.py: PSFv2 @@ -90,6 +90,10 @@ install -m 644 compileall2.py %{buildroot}%{_rpmconfigdir}/redhat/ %changelog +* Fri Apr 16 2021 Miro HronĨok - 3.9-36.1 +- Allow commas as argument separator for extras names in %%python_extras_subpkg +- Fixes: rhbz#1936486 + * Fri Apr 16 2021 Mohan Boddu - 3.9-36 - Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937 diff --git a/tests/test_evals.py b/tests/test_evals.py index 1f931c6..e2909c3 100644 --- a/tests/test_evals.py +++ b/tests/test_evals.py @@ -424,6 +424,47 @@ def test_python_extras_subpkg_underscores(): assert lines == expected +@pytest.mark.parametrize('sep', [pytest.param(('', ' ', ' ', ''), id='spaces'), + pytest.param(('', ',', ',', ''), id='commas'), + pytest.param(('', ',', ',', ','), id='commas-trailing'), + pytest.param((',', ',', ',', ''), id='commas-leading'), + pytest.param((',', ',', ',', ','), id='commas-trailing-leading'), + pytest.param(('', ',', ' ', ''), id='mixture'), + pytest.param((' ', ' ', '\t\t, ', '\t'), id='chaotic-good'), + pytest.param(('', '\t ,, \t\r ', ',,\t , ', ',,'), id='chaotic-evil')]) +def test_python_extras_subpkg_arg_separators(sep): + lines = rpm_eval('%python_extras_subpkg -n python3-hypothesis -F {}cli{}ghostwriter{}pytz{}'.format(*sep), + version='6.6.0', release='1.fc35') + expected = textwrap.dedent(f""" + %package -n python3-hypothesis+cli + Summary: Metapackage for python3-hypothesis: cli extras + Requires: python3-hypothesis = 6.6.0-1.fc35 + %description -n python3-hypothesis+cli + This is a metapackage bringing in cli extras requires for python3-hypothesis. + It makes sure the dependencies are installed. + + + + %package -n python3-hypothesis+ghostwriter + Summary: Metapackage for python3-hypothesis: ghostwriter extras + Requires: python3-hypothesis = 6.6.0-1.fc35 + %description -n python3-hypothesis+ghostwriter + This is a metapackage bringing in ghostwriter extras requires for + python3-hypothesis. + It makes sure the dependencies are installed. + + + + %package -n python3-hypothesis+pytz + Summary: Metapackage for python3-hypothesis: pytz extras + Requires: python3-hypothesis = 6.6.0-1.fc35 + %description -n python3-hypothesis+pytz + This is a metapackage bringing in pytz extras requires for python3-hypothesis. + It makes sure the dependencies are installed. + """).lstrip().splitlines() + assert lines == expected + + @pytest.mark.parametrize('basename_len', [1, 10, 30, 45, 78]) @pytest.mark.parametrize('extra_len', [1, 13, 28, 52, 78]) def test_python_extras_subpkg_description_wrapping(basename_len, extra_len):