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

Fix for src-files not being used when specified in a config file #2015

Merged
merged 6 commits into from
Jan 20, 2024
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
6 changes: 6 additions & 0 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ def cli(
ctx.color = color
log.verbosity = verbose - quiet

# If ``src-files` was not provided as an input, but rather as config,
# it will be part of the click context ``ctx``.
# However, if ``src_files`` is specified, then we want to use that.
if not src_files and ctx.default_map and "src_files" in ctx.default_map:
csalerno-asml marked this conversation as resolved.
Show resolved Hide resolved
src_files = ctx.default_map["src_files"]

if all_build_deps and build_deps_targets:
raise click.BadParameter(
"--build-deps-for has no effect when used with --all-build-deps"
Expand Down
36 changes: 36 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3447,6 +3447,42 @@ def test_allow_in_config_pip_sync_option(pip_conf, runner, tmp_path, make_config
assert "Using pip-tools configuration defaults found" in out.stderr


def test_use_src_files_from_config_if_option_is_not_specified_from_cli(
pip_conf, runner, tmp_path, make_config_file
):
foo_in = tmp_path / "foo.in"
req_in = tmp_path / "requirements.in"

config_file = make_config_file("src-files", [foo_in.as_posix()])

req_in.write_text("small-fake-a==0.1", encoding="utf-8")
foo_in.write_text("small-fake-b==0.1", encoding="utf-8")

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

assert out.exit_code == 0, out
assert "small-fake-b" in out.stderr
assert "small-fake-a" not in out.stderr
csalerno-asml marked this conversation as resolved.
Show resolved Hide resolved


def test_use_src_files_from_cli_if_option_is_specified_in_both_config_and_cli(
pip_conf, runner, tmp_path, make_config_file
):
foo_in = tmp_path / "foo.in"
req_in = tmp_path / "requirements.in"

config_file = make_config_file("src-files", [foo_in.as_posix()])

req_in.write_text("small-fake-a==0.1", encoding="utf-8")
foo_in.write_text("small-fake-b==0.1", encoding="utf-8")

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

assert out.exit_code == 0, out
assert "small-fake-a" in out.stderr
assert "small-fake-b" not in out.stderr


def test_cli_boolean_flag_config_option_has_valid_context(
pip_conf, runner, tmp_path, make_config_file
):
Expand Down