diff --git a/piptools/scripts/options.py b/piptools/scripts/options.py index ab456fce..cae5e2f8 100644 --- a/piptools/scripts/options.py +++ b/piptools/scripts/options.py @@ -245,6 +245,7 @@ def _get_default_option(option_name: str) -> Any: src_files = click.argument( "src_files", nargs=-1, + is_eager=True, type=click.Path(exists=True, allow_dash=True), ) diff --git a/piptools/utils.py b/piptools/utils.py index 3b2061f7..ddbff322 100644 --- a/piptools/utils.py +++ b/piptools/utils.py @@ -630,7 +630,7 @@ def select_config_file(src_files: tuple[str, ...]) -> Path | None: # NOTE: input. working_directory = Path.cwd() src_files_as_paths = ( - (working_directory / src_file).resolve() for src_file in src_files or (".",) + (working_directory / src_file).resolve() for src_file in src_files + (".",) ) candidate_dirs = (src if src.is_dir() else src.parent for src in src_files_as_paths) config_file_path = next( diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index f6c5be66..c816de4d 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3635,3 +3635,13 @@ def test_stdout_should_not_be_read_when_stdin_is_not_a_plain_file( out = runner.invoke(cli, [req_in.as_posix(), "--output-file", fifo.as_posix()]) assert out.exit_code == 0, out + + +def test_config_option_not_unnecessarily_added_in_output_header(runner, tmpdir_cwd): + req_in = tmpdir_cwd / "requirements.in" + req_in.touch() + + out = runner.invoke(cli) + + assert out.exit_code == 0, out + assert "--config" not in out.stderr diff --git a/tests/test_utils.py b/tests/test_utils.py index edf012aa..37743534 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -808,3 +808,16 @@ def test_select_config_file_prefers_pip_tools_toml_over_pyproject_toml(tmpdir_cw ) assert select_config_file(()) == pip_tools_file + + +def test_select_config_file_with_config_file_in_different_directory( + tmpdir_cwd, make_config_file +): + config_file = make_config_file("dry-run", True, ".pip-tools.toml") + + (tmpdir_cwd / "subdir").mkdir() + + requirement_file = Path("subdir/requirements.in") + requirement_file.touch() + + assert select_config_file((requirement_file.as_posix(),)) == config_file