From db7b044f99a471d4213ed6eefc9a29c8c05610b7 Mon Sep 17 00:00:00 2001 From: chrysle Date: Sat, 20 Jan 2024 17:44:04 +0100 Subject: [PATCH 1/2] Fix config file search and inclusion in header --- piptools/scripts/options.py | 1 + piptools/utils.py | 2 +- tests/test_cli_compile.py | 13 +++++++++++++ tests/test_utils.py | 11 +++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) 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..a456bdf8 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3353,6 +3353,9 @@ def test_default_config_option(pip_conf, runner, make_config_file, tmpdir_cwd): out = runner.invoke(cli) + print(out.stdout) + print(out.stderr) + assert out.exit_code == 0 assert "Dry-run, so nothing updated" in out.stderr @@ -3635,3 +3638,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..a1ef494b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -808,3 +808,14 @@ 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 From cbc8f01c0a74be378630508d3d35d38f1b96b2b7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 08:17:16 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_cli_compile.py | 3 --- tests/test_utils.py | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index a456bdf8..c816de4d 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3353,9 +3353,6 @@ def test_default_config_option(pip_conf, runner, make_config_file, tmpdir_cwd): out = runner.invoke(cli) - print(out.stdout) - print(out.stderr) - assert out.exit_code == 0 assert "Dry-run, so nothing updated" in out.stderr diff --git a/tests/test_utils.py b/tests/test_utils.py index a1ef494b..37743534 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -810,7 +810,9 @@ 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): +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()