Skip to content

Commit 3b89744

Browse files
committed
fix(pipstar): correctly handle complex self deps
It seems that with the `pipstar` port there was a typo and the initial tests that we had for Python were insufficient to catch such a regression. The second if statement where we loop through packages again had a `req` instead of `req_` in the `if` statement and the test coverage was not sufficient. I have abstracted the if statement into a function to easier spot such issues and added an extra test to ensure that a regression would be actually caught. With this the Starlark test suite is now officially more robust than the Python version. Fixes #3524
1 parent 9571e2d commit 3b89744

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ END_UNRELEASED_TEMPLATE
7777
Use the `bazel_binary_info` module to access it. The {flag}`--stamp` flag will
7878
add {flag}`--workspace_status` information.
7979

80+
{#v1-8-1}
81+
## [1.8.1] - 2026-01-20
82+
83+
{#v1-8-1-fixed}
84+
### Fixed
85+
* (pipstar) The extra resolution for complex packages is now handled again correctly.
86+
Fixes [#3524](https://github.com/bazel-contrib/rules_python/issues/3524).
87+
8088
{#v1-8-0}
8189
## [1.8.0] - 2025-12-19
8290

python/private/pypi/pep508_deps.bzl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,27 @@ def _resolve_extras(self_name, reqs, extras):
135135

136136
# A double loop is not strictly optimal, but always correct without recursion
137137
for req in self_reqs:
138-
if [True for extra in extras if evaluate(req.marker, env = {"extra": extra})]:
138+
if _evaluate_any(req, extras):
139139
extras = extras + req.extras
140140
else:
141141
continue
142142

143143
# Iterate through all packages to ensure that we include all of the extras from previously
144144
# visited packages.
145145
for req_ in self_reqs:
146-
if [True for extra in extras if evaluate(req.marker, env = {"extra": extra})]:
146+
if _evaluate_any(req_, extras):
147147
extras = extras + req_.extras
148148

149149
# Poor mans set
150150
return sorted({x: None for x in extras})
151151

152+
def _evaluate_any(req, extras):
153+
for extra in extras:
154+
if evaluate(req.marker, env = {"extra": extra}):
155+
return True
156+
157+
return False
158+
152159
def _add_reqs(deps, deps_select, dep, reqs, *, extras):
153160
for req in reqs:
154161
if not req.marker:

tests/pypi/pep508/deps_tests.bzl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def test_self_dependencies_can_come_in_any_order(env):
9090
"baz; extra == 'feat'",
9191
"foo[feat2]; extra == 'all'",
9292
"foo[feat]; extra == 'feat2'",
93+
"foo[feat3]; extra == 'all'",
9394
"zdep; extra == 'all'",
9495
],
9596
extras = ["all"],
@@ -100,6 +101,24 @@ def test_self_dependencies_can_come_in_any_order(env):
100101

101102
_tests.append(test_self_dependencies_can_come_in_any_order)
102103

104+
def test_self_include_deps_from_previously_visited(env):
105+
got = deps(
106+
"foo",
107+
requires_dist = [
108+
"bar",
109+
"baz; extra == 'feat'",
110+
"foo[dev]; extra == 'all'",
111+
"foo[feat]; extra == 'feat2'",
112+
"dev_dep; extra == 'dev'",
113+
],
114+
extras = ["feat2"],
115+
)
116+
117+
env.expect.that_collection(got.deps).contains_exactly(["bar", "baz"])
118+
env.expect.that_dict(got.deps_select).contains_exactly({})
119+
120+
_tests.append(test_self_include_deps_from_previously_visited)
121+
103122
def _test_can_get_deps_based_on_specific_python_version(env):
104123
requires_dist = [
105124
"bar",

0 commit comments

Comments
 (0)