Skip to content

Commit

Permalink
Add --no-config option (#1896)
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev authored Jul 1, 2023
1 parent e543402 commit 407f008
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
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()])

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

0 comments on commit 407f008

Please sign in to comment.