Skip to content

Commit

Permalink
further cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aignas committed Jan 8, 2024
1 parent 8f93931 commit fef4ac5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions python/pip_install/tools/wheel_installer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 9 additions & 8 deletions python/pip_install/tools/wheel_installer/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}",
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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.
Expand Down

0 comments on commit fef4ac5

Please sign in to comment.