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
23 changes: 23 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,29 @@ def test_get_compile_command_with_config(tmpdir_cwd, config_file, expected_comma
assert get_compile_command(ctx) == expected_command


def test_get_compile_command_does_not_include_default_config_if_reqs_file_in_subdir(
tmpdir_cwd,
):
"""
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("pyproject.toml")
default_config_file.touch()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also test the case when the [tool.pip-tools] section is present and empty?

Also, how about a .pip-tools.toml with an empty or missing [tool.pip-tools] and pyproject.toml with a non-empty one? I think that the pyproject.toml shouldn't be taken into account in this case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll add those combinations to parametrized tests 👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 64445d0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping to see what happens if both files exist too..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@atugushev atugushev Jul 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like out of scope of get_compile_command. We can add more detailed unit tests for select_config_file() directly. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's out of the scope, it'd be good to add the tests separately.

Copy link
Member Author

@atugushev atugushev Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed In 845029a


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

with open(req_file, "w"):
pass
atugushev marked this conversation as resolved.
Show resolved Hide resolved

# 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