diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 37bf042b..5b14bc43 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -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" diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 3341f751..f6c5be66 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -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 ):