Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --no-config option #1896

Merged
merged 4 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ def _determine_linesep(
is_eager=True,
callback=override_defaults_from_config_file,
)
@click.option(
"--no-config",
is_flag=True,
default=False,
help="Do not read any config file.",
is_eager=True,
)
def cli(
ctx: click.Context,
verbose: int,
Expand Down Expand Up @@ -358,6 +365,7 @@ def cli(
emit_options: bool,
unsafe_package: tuple[str, ...],
config: Path | None,
no_config: bool,
) -> None:
"""
Compiles requirements.txt from requirements.in, pyproject.toml, setup.cfg,
Expand Down
8 changes: 8 additions & 0 deletions piptools/scripts/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@
is_eager=True,
callback=override_defaults_from_config_file,
)
@click.option(
"--no-config",
is_flag=True,
default=False,
help="Do not read any config file.",
is_eager=True,
)
def cli(
ask: bool,
dry_run: bool,
Expand All @@ -121,6 +128,7 @@ def cli(
src_files: tuple[str, ...],
pip_args: str | None,
config: Path | None,
no_config: bool,
) -> None:
"""Synchronize virtual environment with requirements.txt."""
log.verbosity = verbose - quiet
Expand Down
4 changes: 4 additions & 0 deletions piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"--verbose",
"--cache-dir",
"--no-reuse-hashes",
"--no-config",
}


Expand Down Expand Up @@ -548,6 +549,9 @@ def override_defaults_from_config_file(
file. Those files are searched for in the same directory as the requirements
input file, or the current working directory if requirements come via stdin.
"""
if ctx.params.get("no_config"):
return None

if value is None:
config_file = select_config_file(ctx.params.get("src_files", ()))
if config_file is None:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2973,3 +2973,19 @@ def test_config_option(pip_conf, runner, tmp_path, make_config_file):

assert out.exit_code == 0
assert "Dry-run, so nothing updated" in out.stderr


def test_no_config_option_overrides_config_with_defaults(
pip_conf, runner, tmp_path, make_config_file
):
config_file = make_config_file("dry-run", True)

req_in = tmp_path / "requirements.in"
req_in.touch()

out = runner.invoke(
cli, [req_in.as_posix(), "--no-config", "--config", config_file.as_posix()]
)

assert out.exit_code == 0
assert "Dry-run, so nothing updated" not in out.stderr
13 changes: 13 additions & 0 deletions tests/test_cli_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,16 @@ def test_config_option(run, runner, make_config_file):

assert out.exit_code == 1
assert "Would install:" in out.stdout


@mock.patch("piptools.sync.run")
def test_no_config_option_overrides_config_with_defaults(run, runner, make_config_file):
config_file = make_config_file("dry-run", True)

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

out = runner.invoke(cli, ["--no-config", "--config", config_file.as_posix()])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a separate test with its own name or at least a parametrized case..

Copy link
Member Author

@atugushev atugushev Jul 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I agree, however in this case, I prefer the triangulation technique.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how it's applicable in this case. You're clearly testing two separate behaviors that must appear as separate entries in the test report.
The only way of having two things reported from the same test function is to use pytest-subtest. But it still feels wrong since you're not checking two properties of the same behavior outcome.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, for property-based testing, we should really integrate Hypothesis..

Copy link
Member Author

@atugushev atugushev Jul 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, here you go 65fe40f

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


assert out.exit_code == 0
assert "Would install:" not in out.stdout