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..bd16cd8f 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,25 @@ 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..80ff570b 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,26 @@ 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)