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 inconsistent handling of constraints comments with backtracking resolver #1713

Merged
merged 4 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion piptools/resolver.py
Expand Up @@ -770,7 +770,7 @@ def _get_install_requirement_from_candidate(

# Save source for annotation
source_ireq = self._constraints_map.get(ireq_key)
if source_ireq is not None and ireq_key not in self.existing_constraints:
if source_ireq is not None:
pinned_ireq._source_ireqs = [source_ireq]

return pinned_ireq
37 changes: 37 additions & 0 deletions tests/test_cli_compile.py
Expand Up @@ -2450,3 +2450,40 @@ def test_resolver_reaches_max_rounds(runner):
out = runner.invoke(cli, ["--max-rounds", 0])

assert out.exit_code != 0, out


def test_preserve_via_requirements_constrained_dependencies_when_run_twice(
pip_conf, runner
):
"""
Test that 2 consecutive runs of pip-compile (first with a non-existing requirements.txt file,
second with an existing file) produce the same output.
"""
with open("constraints.txt", "w") as constraints_in:
constraints_in.write("small-fake-a==0.1")

with open("requirements.in", "w") as req_in:
req_in.write("-c constraints.txt\nsmall_fake_with_deps")

cli_arguments = ["--no-emit-options", "--no-header"]

# First run of the command will generate `requirements.txt`, which doesn't yet exist.
first_out = runner.invoke(cli, cli_arguments)

# Second run of the command will update `requirements.txt`.
second_out = runner.invoke(cli, cli_arguments)

expected_output = dedent(
"""\
small-fake-a==0.1
# via
# -c constraints.txt
# small-fake-with-deps
small-fake-with-deps==0.1
# via -r requirements.in
"""
)

for output in (first_out, second_out):
assert output.exit_code == 0, output
assert output.stderr == expected_output