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

Prevent loss of deep dependencies of local requirements #1506

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions piptools/repositories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ def allow_all_wheels(self) -> Iterator[None]:
Monkey patches pip.Wheel to allow wheels from all platforms and Python versions.
"""

@abstractmethod
def copy_ireq_dependencies(
self, source: InstallRequirement, dest: InstallRequirement
) -> None:
"""
Notifies the repository that `dest` is a copy of `source`, and so it
has the same dependencies. Otherwise, once we prepare an ireq to assign
it its name, we would lose track of those dependencies on combining
that ireq with others.
"""

@property
@abstractmethod
def options(self) -> optparse.Values:
Expand Down
5 changes: 5 additions & 0 deletions piptools/repositories/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,8 @@ def get_hashes(self, ireq: InstallRequirement) -> Set[str]:
def allow_all_wheels(self) -> Iterator[None]:
with self.repository.allow_all_wheels():
yield

def copy_ireq_dependencies(
self, source: InstallRequirement, dest: InstallRequirement
) -> None:
self.repository.copy_ireq_dependencies(source, dest)
9 changes: 9 additions & 0 deletions piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ def get_dependencies(self, ireq: InstallRequirement) -> Set[InstallRequirement]:

return self._dependencies_cache[ireq]

def copy_ireq_dependencies(
self, source: InstallRequirement, dest: InstallRequirement
) -> None:
try:
self._dependencies_cache[dest] = self._dependencies_cache[source]
except KeyError:
# `source` may not be in cache yet.
pass

def _get_project(self, ireq: InstallRequirement) -> Any:
"""
Return a dict of a project info from PyPI JSON API for a given
Expand Down
6 changes: 6 additions & 0 deletions piptools/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def combine_install_requirements(

# deepcopy the accumulator so as to not modify the inputs
combined_ireq = copy.deepcopy(source_ireqs[0])
repository.copy_ireq_dependencies(source_ireqs[0], combined_ireq)

for ireq in source_ireqs[1:]:
# NOTE we may be losing some info on dropped reqs here
Expand All @@ -82,6 +83,11 @@ def combine_install_requirements(
if combined_ireq.req is not None:
combined_ireq.req.extras = set(combined_ireq.extras)

for attr in ("link", "local_file_path", "original_link"):
setattr(
combined_ireq, attr, getattr(combined_ireq, attr) or getattr(ireq, attr)
)

# InstallRequirements objects are assumed to come from only one source, and
# so they support only a single comes_from entry. This function breaks this
# model. As a workaround, we deterministically choose a single source for
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def allow_all_wheels(self):
# No need to do an actual pip.Wheel mock here.
yield

def copy_ireq_dependencies(self, source, dest):
# No state to update.
pass

@property
def options(self) -> optparse.Values:
"""Not used"""
Expand Down