Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix revealed default config in header if requirements in subfolder #1904

Merged
merged 15 commits into from
Aug 7, 2023
5 changes: 3 additions & 2 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ def _determine_linesep(
default=10,
help="Maximum number of rounds before resolving the requirements aborts.",
)
@click.argument("src_files", nargs=-1, type=click.Path(exists=True, allow_dash=True))
@click.argument(
"src_files", nargs=-1, type=click.Path(exists=True, allow_dash=True), is_eager=True
)
@click.option(
"--build-isolation/--no-build-isolation",
is_flag=True,
Expand Down Expand Up @@ -316,7 +318,6 @@ def _determine_linesep(
),
help=f"Read configuration from TOML file. By default, looks for a {CONFIG_FILE_NAME} or "
"pyproject.toml.",
is_eager=True,
callback=override_defaults_from_config_file,
)
@click.option(
Expand Down
5 changes: 3 additions & 2 deletions piptools/scripts/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@
help="Path to SSL client certificate, a single file containing "
"the private key and the certificate in PEM format.",
)
@click.argument("src_files", required=False, type=click.Path(exists=True), nargs=-1)
@click.argument(
"src_files", required=False, type=click.Path(exists=True), nargs=-1, is_eager=True
)
@click.option("--pip-args", help="Arguments to pass directly to pip install.")
@click.option(
"--config",
Expand All @@ -100,7 +102,6 @@
),
help=f"Read configuration from TOML file. By default, looks for a {CONFIG_FILE_NAME} or "
"pyproject.toml.",
is_eager=True,
callback=override_defaults_from_config_file,
)
@click.option(
Expand Down
30 changes: 30 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,36 @@ def test_get_compile_command_with_config(tmpdir_cwd, config_file, expected_comma
assert get_compile_command(ctx) == expected_command


@pytest.mark.parametrize("config_file", ("pyproject.toml", ".pip-tools.toml"))
@pytest.mark.parametrize(
"config_file_content",
(
pytest.param("", id="empty config file"),
pytest.param("[tool.pip-tools]", id="empty config section"),
pytest.param("[tool.pip-tools]\ndry-run = True", id="non-empty config section"),
),
)
def test_get_compile_command_does_not_include_default_config_if_reqs_file_in_subdir(
tmpdir_cwd, config_file, config_file_content
):
"""
Test that ``get_compile_command`` does not include default config file
if requirements file is in a subdirectory.
Regression test for issue GH-1903.
"""
default_config_file = Path(config_file)
default_config_file.write_text(config_file_content)

(tmpdir_cwd / "subdir").mkdir()
req_file = Path("subdir/requirements.in")
req_file.touch()
req_file.write_bytes(b"")

# Make sure that the default config file is not included
with compile_cli.make_context("pip-compile", [req_file.as_posix()]) as ctx:
assert get_compile_command(ctx) == f"pip-compile {req_file.as_posix()}"


def test_get_compile_command_escaped_filenames(tmpdir_cwd):
"""
Test that get_compile_command output (re-)escapes ' -- '-escaped filenames.
Expand Down