Skip to content

Commit

Permalink
Support passing the same key multiple times in --config-settings
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Laíns <lains@riseup.net>
  • Loading branch information
FFY00 committed Mar 10, 2023
1 parent 4b14e7c commit 07f906c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,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(
Expand Down
13 changes: 10 additions & 3 deletions tests/unit/test_pyproject_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,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, expected) -> 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

0 comments on commit 07f906c

Please sign in to comment.