From 4de6dc6a5925b779681ffb33f57718041bf5d365 Mon Sep 17 00:00:00 2001 From: Dmitry Meyer Date: Fri, 31 May 2024 06:57:59 +0000 Subject: [PATCH 1/2] Fix config file discovery in src_files directories Fixes: https://github.com/jazzband/pip-tools/issues/2096 --- piptools/scripts/options.py | 1 + tests/test_cli_compile.py | 18 ++++++++++++++++++ tests/test_cli_sync.py | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/piptools/scripts/options.py b/piptools/scripts/options.py index 98fbbf7a..220a1a85 100644 --- a/piptools/scripts/options.py +++ b/piptools/scripts/options.py @@ -246,6 +246,7 @@ def _get_default_option(option_name: str) -> Any: "src_files", nargs=-1, type=click.Path(exists=True, allow_dash=True), + is_eager=True, ) build_isolation = click.option( diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index c5031fc2..24d1476a 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -17,6 +17,7 @@ from pip._vendor.packaging.version import Version from piptools.build import ProjectMetadata +from piptools.locations import DEFAULT_CONFIG_FILE_NAMES from piptools.scripts.compile import cli from piptools.utils import ( COMPILE_EXCLUDE_OPTIONS, @@ -3493,6 +3494,23 @@ def test_default_config_option(pip_conf, runner, make_config_file, tmpdir_cwd): assert "Dry-run, so nothing updated" in out.stderr +@pytest.mark.parametrize("config_file_name", DEFAULT_CONFIG_FILE_NAMES) +def test_default_config_in_requirements_dir( + pip_conf, runner, make_config_file, tmpdir_cwd, config_file_name +): + make_config_file("dry-run", True, config_file_name=f"requirements/{config_file_name}") + + req_dir = tmpdir_cwd / "requirements" + req_dir.mkdir(exist_ok=True, parents=True) + req_in = req_dir / "requirements.in" + req_in.touch() + + out = runner.invoke(cli, [req_in.as_posix()]) + + assert out.exit_code == 0, out.stderr + assert "Dry-run, so nothing updated" in out.stderr + + def test_no_config_option_overrides_config_with_defaults( pip_conf, runner, tmp_path, make_config_file ): diff --git a/tests/test_cli_sync.py b/tests/test_cli_sync.py index 5e69770f..cab89fb3 100644 --- a/tests/test_cli_sync.py +++ b/tests/test_cli_sync.py @@ -8,6 +8,7 @@ import pytest from pip._vendor.packaging.version import Version +from piptools.locations import DEFAULT_CONFIG_FILE_NAMES from piptools.scripts import sync from piptools.scripts.sync import cli @@ -387,6 +388,24 @@ def test_default_config_option(run, runner, make_config_file, tmpdir_cwd): assert "Would install:" in out.stdout +@pytest.mark.parametrize("config_file_name", DEFAULT_CONFIG_FILE_NAMES) +@mock.patch("piptools.sync.run") +def test_default_config_in_requirements_dir( + run, runner, make_config_file, tmpdir_cwd, config_file_name +): + make_config_file("dry-run", True, config_file_name=f"requirements/{config_file_name}") + + req_dir = tmpdir_cwd / "requirements" + req_dir.mkdir(exist_ok=True, parents=True) + req_in = req_dir / "requirements.txt" + req_in.write_text("six==1.10.0") + + out = runner.invoke(cli, [req_in.as_posix()]) + + assert out.exit_code == 1, out.stderr + assert "Would install:" in out.stdout + + @mock.patch("piptools.sync.run") def test_config_option(run, runner, make_config_file): config_file = make_config_file("dry-run", True) From 39900e46402bee3cf838868c0230f920435ed234 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 31 May 2024 07:01:54 +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 | 4 +++- tests/test_cli_sync.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 24d1476a..bd16cd8f 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3498,7 +3498,9 @@ def test_default_config_option(pip_conf, runner, make_config_file, tmpdir_cwd): def test_default_config_in_requirements_dir( pip_conf, runner, make_config_file, tmpdir_cwd, config_file_name ): - make_config_file("dry-run", True, config_file_name=f"requirements/{config_file_name}") + make_config_file( + "dry-run", True, config_file_name=f"requirements/{config_file_name}" + ) req_dir = tmpdir_cwd / "requirements" req_dir.mkdir(exist_ok=True, parents=True) diff --git a/tests/test_cli_sync.py b/tests/test_cli_sync.py index cab89fb3..80ff570b 100644 --- a/tests/test_cli_sync.py +++ b/tests/test_cli_sync.py @@ -393,7 +393,9 @@ def test_default_config_option(run, runner, make_config_file, tmpdir_cwd): def test_default_config_in_requirements_dir( run, runner, make_config_file, tmpdir_cwd, config_file_name ): - make_config_file("dry-run", True, config_file_name=f"requirements/{config_file_name}") + make_config_file( + "dry-run", True, config_file_name=f"requirements/{config_file_name}" + ) req_dir = tmpdir_cwd / "requirements" req_dir.mkdir(exist_ok=True, parents=True)