Skip to content

Commit

Permalink
Ensure editables that are both primary reqs and constraints
Browse files Browse the repository at this point in the history
appear in pip-compile output
  • Loading branch information
richafrank committed Mar 31, 2020
1 parent 692f6be commit b677a52
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
10 changes: 2 additions & 8 deletions piptools/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def combine_install_requirements(ireqs):
combined_ireq = copy.deepcopy(source_ireqs[0])
for ireq in source_ireqs[1:]:
# NOTE we may be losing some info on dropped reqs here
combined_ireq.req.specifier &= ireq.req.specifier
if combined_ireq.req is not None and ireq.req is not None:
combined_ireq.req.specifier &= ireq.req.specifier
combined_ireq.constraint &= ireq.constraint
# Return a sorted, de-duped tuple of extras
combined_ireq.extras = tuple(
Expand Down Expand Up @@ -220,13 +221,6 @@ def _group_constraints(self, constraints):
"""
for _, ireqs in full_groupby(constraints, key=key_from_ireq):
ireqs = list(ireqs)
editable_ireq = next((ireq for ireq in ireqs if ireq.editable), None)
if editable_ireq:
# ignore all the other specs: the editable one is the one that counts
yield editable_ireq
continue

yield combine_install_requirements(ireqs)

def _resolve_one_round(self):
Expand Down
23 changes: 23 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,29 @@ def test_editable_package(pip_conf, runner):
assert "small-fake-a==0.1" in out.stderr


@pytest.mark.parametrize(("req_editable",), [(True,), (False,)])
def test_editable_package_in_constraints(pip_conf, runner, req_editable):
"""
piptools can compile an editable that appears in both primary requirements
and constraints
"""
fake_package_dir = os.path.join(PACKAGES_PATH, "small_fake_with_deps")
fake_package_dir = path_to_url(fake_package_dir)

with open("constraints.txt", "w") as constraints_in:
constraints_in.write("-e " + fake_package_dir)

with open("requirements.in", "w") as req_in:
prefix = "-e " if req_editable else ""
req_in.write(prefix + fake_package_dir + "\n-c constraints.txt")

out = runner.invoke(cli, ["-n"])

assert out.exit_code == 0
assert fake_package_dir in out.stderr
assert "small-fake-a==0.1" in out.stderr


@pytest.mark.network
def test_editable_package_vcs(runner):
vcs_package = (
Expand Down

0 comments on commit b677a52

Please sign in to comment.