Skip to content

Commit

Permalink
Merge branch 'main' into fix-1932
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev authored Jul 25, 2023
2 parents 9e54941 + 7386d28 commit f77b835
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
20 changes: 0 additions & 20 deletions piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,17 +673,6 @@ def select_config_file(src_files: tuple[str, ...]) -> Path | None:
}


# Ensure that any default overrides for these click options are lists, supporting multiple values
MULTIPLE_VALUE_OPTIONS = [
"extras",
"upgrade_packages",
"unsafe_package",
"find_links",
"extra_index_url",
"trusted_host",
]


def get_cli_options(ctx: click.Context) -> dict[str, click.Parameter]:
cli_opts = {
opt: option
Expand Down Expand Up @@ -712,20 +701,11 @@ def parse_config_file(

# In a TOML file, we expect the config to be under `[tool.pip-tools]`
piptools_config: dict[str, Any] = config.get("tool", {}).get("pip-tools", {})

piptools_config = _normalize_keys_in_config(piptools_config)
piptools_config = _invert_negative_bool_options_in_config(
ctx=click_context,
config=piptools_config,
)

# Any option with multiple values needs to be a list in the pyproject.toml
for mv_option in MULTIPLE_VALUE_OPTIONS:
if not isinstance(piptools_config.get(mv_option), (list, type(None))):
original_option = mv_option.replace("_", "-")
raise click.BadOptionUsage(
original_option, f"Config key '{original_option}' must be a list"
)
return piptools_config


Expand Down
24 changes: 14 additions & 10 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,21 +624,25 @@ def test_callback_config_file_defaults(pyproject_param, new_default, make_config


@pytest.mark.parametrize(
"mv_option",
("param", "value"),
(
"extra",
"upgrade-package",
"unsafe-package",
"find-links",
"extra-index-url",
"trusted-host",
("extra", "not-a-list"),
("upgrade_package", "not-a-list"),
("unsafe_package", "not-a-list"),
("find_links", "not-a-list"),
("extra_index_url", "not-a-list"),
("trusted_host", "not-a-list"),
("annotate", "not-a-bool"),
("max_rounds", "not-an-int"),
),
)
def test_callback_config_file_defaults_multi_value_options(mv_option, make_config_file):
config_file = make_config_file(mv_option, "not-a-list")
def test_callback_config_file_defaults_multi_validate_value(
param, value, make_config_file
):
config_file = make_config_file(param, value)
ctx = Context(compile_cli)
ctx.params["src_files"] = (str(config_file),)
with pytest.raises(BadOptionUsage, match="must be a list"):
with pytest.raises(BadOptionUsage, match="Invalid value for config key"):
override_defaults_from_config_file(ctx, "config", None)


Expand Down

0 comments on commit f77b835

Please sign in to comment.