Skip to content

Commit

Permalink
Merge pull request #2015 from csalerno-asml/fix-2006
Browse files Browse the repository at this point in the history
Fix for `src-files` not being used when specified in a config file
  • Loading branch information
chrysle committed Jan 20, 2024
2 parents dee50c4 + e216ad5 commit d673c8e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions piptools/scripts/compile.py
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:
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
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


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

0 comments on commit d673c8e

Please sign in to comment.