From d14a2dbc5409882526ede1b969724bf7c694a996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 30 May 2023 10:01:40 +0200 Subject: [PATCH] Accept multiple values for the same config settings --- pyproject_wheel.py | 21 +++++++++++++++------ tests/config-settings-test.spec | 8 ++++---- tests/config_settings_test_backend.py | 13 +++++++++++-- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/pyproject_wheel.py b/pyproject_wheel.py index 2aab1e9..6d62176 100644 --- a/pyproject_wheel.py +++ b/pyproject_wheel.py @@ -13,7 +13,13 @@ def parse_config_settings_args(config_settings): new_config_settings = {} for arg in config_settings: key, _, value = arg.partition('=') - new_config_settings[key] = value + if key in new_config_settings: + if not isinstance(new_config_settings[key], list): + # convert the existing value to a list + new_config_settings[key] = [new_config_settings[key]] + new_config_settings[key].append(value) + else: + new_config_settings[key] = value return new_config_settings @@ -24,11 +30,14 @@ def get_config_settings_args(config_settings): """ if not config_settings: return - for key, value in config_settings.items(): - if value == '': - yield f'--config-settings={key}' - else: - yield f'--config-settings={key}={value}' + for key, values in config_settings.items(): + if not isinstance(values, list): + values = [values] + for value in values: + if value == '': + yield f'--config-settings={key}' + else: + yield f'--config-settings={key}={value}' def build_wheel(*, wheeldir, stdout=None, config_settings=None): diff --git a/tests/config-settings-test.spec b/tests/config-settings-test.spec index cc622ae..15f2467 100644 --- a/tests/config-settings-test.spec +++ b/tests/config-settings-test.spec @@ -27,7 +27,7 @@ cat <<'EOF' >pyproject.toml [build-system] build-backend = "config_settings_test_backend" backend-path = ["."] -requires = ["flit-core"] +requires = ["flit-core", "packaging", "pip"] [project] name = "config_settings" @@ -37,12 +37,12 @@ EOF %generate_buildrequires -%pyproject_buildrequires -C abc=123 -C xyz=456 -C--option-with-dashes=1 -%pyproject_buildrequires -C abc=123 -C xyz=456 -C--option-with-dashes=1 -w +%pyproject_buildrequires -C abc=123 -C xyz=456 -C--option-with-dashes=1 -C--option-with-dashes=2 +%{!?el9:%pyproject_buildrequires -C abc=123 -C xyz=456 -C--option-with-dashes=1 -C--option-with-dashes=2 -w} %build -%pyproject_wheel -C abc=123 -C xyz=456 -C--option-with-dashes=1 +%{!?el9:%pyproject_wheel -C abc=123 -C xyz=456 -C--option-with-dashes=1 -C--option-with-dashes=2} %changelog diff --git a/tests/config_settings_test_backend.py b/tests/config_settings_test_backend.py index 22d1fba..80f8a2c 100644 --- a/tests/config_settings_test_backend.py +++ b/tests/config_settings_test_backend.py @@ -4,13 +4,22 @@ It is not compliant with PEP 517 and omits some required hooks. """ from flit_core import buildapi +from packaging.version import parse +from pip import __version__ as pip_version -EXPECTED_CONFIG_SETTINGS = {"abc": "123", "xyz": "456", "--option-with-dashes": "1"} +EXPECTED_CONFIG_SETTINGS = [{"abc": "123", "xyz": "456", "--option-with-dashes": ["1", "2"]}] +# Older pip did not accept multiple values, +# but we might backport that later, +# hence we accept it both ways with older pips +if parse(pip_version) < parse("23.1"): + EXPECTED_CONFIG_SETTINGS.append( + EXPECTED_CONFIG_SETTINGS[0] | {"--option-with-dashes": "2"} + ) def _verify_config_settings(config_settings): print(f"config_settings={config_settings}") - if config_settings != EXPECTED_CONFIG_SETTINGS: + if config_settings not in EXPECTED_CONFIG_SETTINGS: raise ValueError( f"{config_settings!r} does not match expected {EXPECTED_CONFIG_SETTINGS!r}" )