Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and chrysle committed Nov 24, 2023
1 parent 03c6cd5 commit 3183a2e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ dry-run = true
```

This does not affect the `pip-sync` command, which also has a `--dry-run` option.
Note that local settings take preference over the global ones of the same name,
whenever both are declared, thus this would also make `pip-compile` generate hashes,
Note that local settings take preference over the global ones of the same name,
whenever both are declared, thus this would also make `pip-compile` generate hashes,
but discard the global dry-run setting:

```toml
Expand Down
39 changes: 20 additions & 19 deletions piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,7 @@ def override_defaults_from_config_file(
else:
config_file = Path(value)

config = parse_config_file(
ctx, config_file
)
config = parse_config_file(ctx, config_file)

_validate_config(ctx, config)
_assign_config_to_cli_context(ctx, config)
Expand Down Expand Up @@ -683,26 +681,29 @@ def parse_config_file(
# In a TOML file, we expect the config to be under `[tool.pip-tools]`,
# `[tool.pip-compile]` or `[tool.pip-sync]`
piptools_config: dict[str, Any] = config.get("tool", {}).get("pip-tools", {})
pipcompile_config: dict[str, Any] = config.get("tool", {}).get("pip-tools", {}).get("compile", {})
pipsync_config: dict[str, Any] = config.get("tool", {}).get("pip-tools", {}).get("sync", {})
pipcompile_config: dict[str, Any] = (
config.get("tool", {}).get("pip-tools", {}).get("compile", {})
)
pipsync_config: dict[str, Any] = (
config.get("tool", {}).get("pip-tools", {}).get("sync", {})
)

config = piptools_config

if click_context.command.name == "pip-compile":
config.pop("compile")
config.update(pipcompile_config)
if pipcompile_config:
config.pop("compile")
config.update(pipcompile_config)
elif click_context.command.name == "pip-sync":
config.pop("sync")
config.update(pipsync_config)

print(config)

if config:
config = _normalize_keys_in_config(config)
config = _invert_negative_bool_options_in_config(
ctx=click_context,
config=config,
)
if pipsync_config:
config.pop("sync")
config.update(pipsync_config)

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

return config

Expand Down
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,21 @@ def _maker(
new_default: Any,
config_file_name: str = DEFAULT_CONFIG_FILE_NAMES[0],
section: str = "pip-tools",
subsection: str | None = None,
) -> Path:
# Create a nested directory structure if config_file_name includes directories
config_dir = (tmpdir_cwd / config_file_name).parent
config_dir.mkdir(exist_ok=True, parents=True)

# Make a config file with this one config default override
config_file = tmpdir_cwd / config_file_name
config_to_dump = {"tool": {section: {pyproject_param: new_default}}}

if subsection:
config_to_dump = {
"tool": {section: {subsection: {pyproject_param: new_default}}}
}
else:
config_to_dump = {"tool": {section: {pyproject_param: new_default}}}
config_file.write_text(tomli_w.dumps(config_to_dump))
return cast(Path, config_file.relative_to(tmpdir_cwd))

Expand Down
7 changes: 6 additions & 1 deletion tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3565,7 +3565,12 @@ def test_origin_of_extra_requirement_not_written_to_annotations(


def test_tool_specific_config_option(pip_conf, runner, tmp_path, make_config_file):
config_file = make_config_file("dry-run", True, section="pip-tools.compile")
config_file = make_config_file(
"dry-run", True, section="pip-tools", subsection="compile"
)

with open(config_file.as_posix()) as f:
print(f.read())

req_in = tmp_path / "requirements.in"
req_in.touch()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def test_allow_in_config_pip_compile_option(run, runner, tmp_path, make_config_f

@mock.patch("piptools.sync.run")
def test_tool_specific_config_option(run, runner, make_config_file):
config_file = make_config_file("dry-run", True, section="pip-sync")
config_file = make_config_file("dry-run", True, section="pip-tools", subsection="sync")

with open(sync.DEFAULT_REQUIREMENTS_FILE, "w") as reqs_txt:
reqs_txt.write("six==1.10.0")
Expand Down

0 comments on commit 3183a2e

Please sign in to comment.