diff --git a/python/pip_install/tools/wheel_installer/BUILD.bazel b/python/pip_install/tools/wheel_installer/BUILD.bazel index 7fd3fd5f23..a396488d3d 100644 --- a/python/pip_install/tools/wheel_installer/BUILD.bazel +++ b/python/pip_install/tools/wheel_installer/BUILD.bazel @@ -54,10 +54,10 @@ py_test( srcs = [ "wheel_test.py", ], - data = [ - "//examples/wheel:minimal_with_py_package", + data = ["//examples/wheel:minimal_with_py_package"], + deps = [ + ":lib", ], - deps = [":lib"], ) py_test( diff --git a/python/pip_install/tools/wheel_installer/wheel.py b/python/pip_install/tools/wheel_installer/wheel.py index 92aeb38217..a67756e34f 100644 --- a/python/pip_install/tools/wheel_installer/wheel.py +++ b/python/pip_install/tools/wheel_installer/wheel.py @@ -247,9 +247,10 @@ def __init__( self.name: str = Deps._normalize(name) self._platforms: Set[Platform] = platforms or set() - # Sort so that the dictionary order in the final order is deterministic - # because Python retains insertion order. That way the build() method - # and unit-tests can be simpler. + # Sort so that the dictionary order in the FrozenDeps is deterministic + # without the final sort because Python retains insertion order. That way + # the sorting by platform is limited within the Platform class itself and + # the unit-tests for the Deps can be simpler. reqs = sorted( (Requirement(wheel_req) for wheel_req in requires_dist), key=lambda x: f"{x.name}:{sorted(x.extras)}", @@ -266,8 +267,7 @@ def __init__( def _add(self, dep: str, platform: Optional[Platform]): dep = Deps._normalize(dep) - # Packages may create dependency cycles when specifying optional-dependencies / 'extras'. - # Example: github.com/google/etils/blob/a0b71032095db14acf6b33516bca6d885fe09e35/pyproject.toml#L32. + # Self-edges are processed in _resolve_extras if dep == self.name: return @@ -278,11 +278,9 @@ def _add(self, dep: str, platform: Optional[Platform]): # Add the platform-specific dep self._select[platform].add(dep) - all_specializations = list(platform.all_specializations()) - # Add the dep to specializations of the given platform if they # exist in the select statement. - for p in all_specializations: + for p in platform.all_specializations(): if p not in self._select: continue @@ -295,6 +293,7 @@ def _add(self, dep: str, platform: Optional[Platform]): # existing dependencies from less specialized platforms are propagated # to the newly added dependency set. for p, deps in self._select.items(): + # Check if the existing platform overlaps with the given platform if p == platform or platform not in p.all_specializations(): continue @@ -313,6 +312,8 @@ def _resolve_extras( `etils`, where we have one set of extras as aliases for other extras and we have an extra called 'all' that includes all other extras. + Example: github.com/google/etils/blob/a0b71032095db14acf6b33516bca6d885fe09e35/pyproject.toml#L32. + When the `requirements.txt` is generated by `pip-tools`, then it is likely that this step is not needed, but for other `requirements.txt` files this may be useful.