From 2ecbed74410bf24110e8a3d3bb23b633ab28334f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 30 Sep 2020 22:31:07 +0200 Subject: [PATCH] Support multiple -x options for %pyproject_buildrequires Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1877978 --- pyproject-rpm-macros.spec | 2 ++ pyproject_buildrequires.py | 13 +++++++------ pyproject_buildrequires_testcases.yaml | 7 +++++-- test_pyproject_buildrequires.py | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index 3c681e0..f6617f1 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -97,7 +97,9 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856 * Tue Sep 29 2020 Lumír Balhar - 0-30 - Process RECORD files in %%pyproject_install and remove them - Support the extras configuration option of tox in %%pyproject_buildrequires -t +- Support multiple -x options for %%pyproject_buildrequires - Fixes: rhbz#1877977 +- Fixes: rhbz#1877978 * Wed Sep 23 2020 Miro Hrončok - 0-29 - Check the requirements after installing "requires_for_build_wheel" diff --git a/pyproject_buildrequires.py b/pyproject_buildrequires.py index f20c378..36139eb 100644 --- a/pyproject_buildrequires.py +++ b/pyproject_buildrequires.py @@ -49,13 +49,14 @@ def hook_call(): class Requirements: """Requirement printer""" - def __init__(self, get_installed_version, extras='', + def __init__(self, get_installed_version, extras=None, generate_extras=False, python3_pkgversion='3'): self.get_installed_version = get_installed_version self.extras = set() if extras: - self.add_extras(*extras.split(',')) + for extra in extras: + self.add_extras(*extra.split(',')) self.missing_requirements = False @@ -276,7 +277,7 @@ def python3dist(name, op=None, version=None, python3_pkgversion="3"): def generate_requires( - *, include_runtime=False, toxenv=None, extras='', + *, include_runtime=False, toxenv=None, extras=None, get_installed_version=importlib_metadata.version, # for dep injection generate_extras=False, python3_pkgversion="3", ): @@ -285,7 +286,7 @@ def generate_requires( This is the main Python entry point. """ requirements = Requirements( - get_installed_version, extras=extras, + get_installed_version, extras=extras or [], generate_extras=generate_extras, python3_pkgversion=python3_pkgversion ) @@ -321,9 +322,9 @@ def main(argv): '(implies --runtime)'), ) parser.add_argument( - '-x', '--extras', metavar='EXTRAS', default='', + '-x', '--extras', metavar='EXTRAS', action='append', help='comma separated list of "extras" for runtime requirements ' - '(e.g. -x testing,feature-x) (implies --runtime)', + '(e.g. -x testing,feature-x) (implies --runtime, can be repeated)', ) parser.add_argument( '--generate-extras', action='store_true', diff --git a/pyproject_buildrequires_testcases.yaml b/pyproject_buildrequires_testcases.yaml index 3f534a3..0f380f4 100644 --- a/pyproject_buildrequires_testcases.yaml +++ b/pyproject_buildrequires_testcases.yaml @@ -238,7 +238,8 @@ Run dependencies with extras (selected): wheel: 1 pyyaml: 1 include_runtime: true - extras: testing + extras: + - testing setup.py: *pytest_setup_py expected: | python3dist(setuptools) >= 40.8 @@ -264,7 +265,9 @@ Run dependencies with multiple extras: wheel: 1 pyyaml: 1 include_runtime: true - extras: testing,more-testing, even-more-testing , cool-feature + extras: + - testing,more-testing + - even-more-testing , cool-feature setup.py: | from setuptools import setup setup( diff --git a/test_pyproject_buildrequires.py b/test_pyproject_buildrequires.py index 46b36d2..cc7ea4e 100644 --- a/test_pyproject_buildrequires.py +++ b/test_pyproject_buildrequires.py @@ -43,7 +43,7 @@ def test_data(case_name, capsys, tmp_path, monkeypatch): generate_requires( get_installed_version=get_installed_version, include_runtime=case.get('include_runtime', False), - extras=case.get('extras', ''), + extras=case.get('extras', []), toxenv=case.get('toxenv', None), generate_extras=case.get('generate_extras', False), )