Accept multiple values for the same config settings
This commit is contained in:
parent
590154b68c
commit
d14a2dbc54
@ -13,6 +13,12 @@ def parse_config_settings_args(config_settings):
|
||||
new_config_settings = {}
|
||||
for arg in config_settings:
|
||||
key, _, value = arg.partition('=')
|
||||
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,7 +30,10 @@ def get_config_settings_args(config_settings):
|
||||
"""
|
||||
if not config_settings:
|
||||
return
|
||||
for key, value in config_settings.items():
|
||||
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:
|
||||
|
@ -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
|
||||
|
@ -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}"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user