Skip to content

Commit

Permalink
Fix inconsistent handling of constraints comments with backtracking r…
Browse files Browse the repository at this point in the history
…esolver (#1713)
  • Loading branch information
mkniewallner committed Nov 5, 2022
1 parent f90fcf3 commit 77318ca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion piptools/resolver.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 77318ca

Please sign in to comment.