Accept multiple values for the same config settings

This commit is contained in:
Miro Hrončok 2023-05-30 10:01:40 +02:00
parent 590154b68c
commit d14a2dbc54
3 changed files with 30 additions and 12 deletions

View File

@ -13,7 +13,13 @@ def parse_config_settings_args(config_settings):
new_config_settings = {} new_config_settings = {}
for arg in config_settings: for arg in config_settings:
key, _, value = arg.partition('=') 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 return new_config_settings
@ -24,11 +30,14 @@ def get_config_settings_args(config_settings):
""" """
if not config_settings: if not config_settings:
return return
for key, value in config_settings.items(): for key, values in config_settings.items():
if value == '': if not isinstance(values, list):
yield f'--config-settings={key}' values = [values]
else: for value in values:
yield f'--config-settings={key}={value}' if value == '':
yield f'--config-settings={key}'
else:
yield f'--config-settings={key}={value}'
def build_wheel(*, wheeldir, stdout=None, config_settings=None): def build_wheel(*, wheeldir, stdout=None, config_settings=None):

View File

@ -27,7 +27,7 @@ cat <<'EOF' >pyproject.toml
[build-system] [build-system]
build-backend = "config_settings_test_backend" build-backend = "config_settings_test_backend"
backend-path = ["."] backend-path = ["."]
requires = ["flit-core"] requires = ["flit-core", "packaging", "pip"]
[project] [project]
name = "config_settings" name = "config_settings"
@ -37,12 +37,12 @@ EOF
%generate_buildrequires %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 -C--option-with-dashes=2
%pyproject_buildrequires -C abc=123 -C xyz=456 -C--option-with-dashes=1 -w %{!?el9:%pyproject_buildrequires -C abc=123 -C xyz=456 -C--option-with-dashes=1 -C--option-with-dashes=2 -w}
%build %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 %changelog

View File

@ -4,13 +4,22 @@ It is not compliant with PEP 517 and omits some required hooks.
""" """
from flit_core import buildapi 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): def _verify_config_settings(config_settings):
print(f"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( raise ValueError(
f"{config_settings!r} does not match expected {EXPECTED_CONFIG_SETTINGS!r}" f"{config_settings!r} does not match expected {EXPECTED_CONFIG_SETTINGS!r}"
) )