mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Support passing the same key multiple times in --config-settings (#11853)
This commit is contained in:
parent
5c3d1fed4a
commit
1268487cba
3 changed files with 23 additions and 4 deletions
4
news/11681.feature.rst
Normal file
4
news/11681.feature.rst
Normal file
|
@ -0,0 +1,4 @@
|
|||
The ``--config-settings``/``-C`` option now supports using the same key multiple
|
||||
times. When the same key is specified multiple times, all values are passed to
|
||||
the build backend as a list, as opposed to the previous behavior where pip would
|
||||
only pass the last value is the same key was used multiple times.
|
|
@ -824,7 +824,13 @@ def _handle_config_settings(
|
|||
if dest is None:
|
||||
dest = {}
|
||||
setattr(parser.values, option.dest, dest)
|
||||
dest[key] = val
|
||||
if key in dest:
|
||||
if isinstance(dest[key], list):
|
||||
dest[key].append(val)
|
||||
else:
|
||||
dest[key] = [dest[key], val]
|
||||
else:
|
||||
dest[key] = val
|
||||
|
||||
|
||||
config_settings: Callable[..., Option] = partial(
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from typing import Dict, List
|
||||
|
||||
import pytest
|
||||
|
||||
from pip._internal.commands import create_command
|
||||
|
@ -36,9 +38,16 @@ def test_set_config_empty_value() -> None:
|
|||
assert options.config_settings == {"x": ""}
|
||||
|
||||
|
||||
def test_replace_config_value() -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("passed", "expected"),
|
||||
[
|
||||
(["x=hello", "x=world"], {"x": ["hello", "world"]}),
|
||||
(["x=hello", "x=world", "x=other"], {"x": ["hello", "world", "other"]}),
|
||||
],
|
||||
)
|
||||
def test_multiple_config_values(passed: List[str], expected: Dict[str, str]) -> None:
|
||||
i = create_command("install")
|
||||
options, _ = i.parse_args(
|
||||
["xxx", "--config-settings", "x=hello", "--config-settings", "x=world"]
|
||||
["xxx", *(f"--config-settings={option}" for option in passed)]
|
||||
)
|
||||
assert options.config_settings == {"x": "world"}
|
||||
assert options.config_settings == expected
|
||||
|
|
Loading…
Reference in a new issue