Skip to content

Commit a9056b1

Browse files
aignasrickeylev
andauthored
chore: enable pipstar for experimental_index_url users (#3428)
`bazel query` may break if users right now rely on the behaviour of: > only host platform packages are present in the whl_library instances When we enabled `pipstar` by default, one of our user reported this breakage because: 1. The `triton` dependency is only used on `linux` and it is in one of the `requirements` files. 2. On mac, this dependency did not have a `whl_library` repository materialized and the bazel query failed because of this reason. Hence we enable `pipstar` in a different way - we only enable it when whl files are downloaded via the bazel downloader and `bazel query` is less likely to fail if you can use the bazel downloader for all of your deps. Work towards #2949 --------- Co-authored-by: Richard Levasseur <[email protected]>
1 parent 235cc00 commit a9056b1

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ END_UNRELEASED_TEMPLATE
7272
### Changed
7373
* (toolchains) Use toolchains from the [20251031] release.
7474
* (gazelle) Internally split modules mapping generation to be per-wheel for concurrency and caching.
75+
* (pip) `pipstar` has been enabled for all `whl_library` instances where the whl
76+
is passed through a label or downloaded using the bazel downloader
77+
([#2949](https://github.com/bazel-contrib/rules_python/issues/2949)).
7578

7679
{#v0-0-0-fixed}
7780
### Fixed

python/private/pypi/hub_builder.bzl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def _pip_parse(self, module_ctx, pip_attr):
146146
self,
147147
module_ctx,
148148
pip_attr = pip_attr,
149+
enable_pipstar = self._config.enable_pipstar or self._get_index_urls.get(pip_attr.python_version),
149150
)
150151

151152
### end of PUBLIC methods
@@ -188,7 +189,7 @@ def _add_extra_aliases(self, extra_hub_aliases):
188189
{alias: True for alias in aliases},
189190
)
190191

191-
def _add_whl_library(self, *, python_version, whl, repo):
192+
def _add_whl_library(self, *, python_version, whl, repo, enable_pipstar):
192193
if repo == None:
193194
# NOTE @aignas 2025-07-07: we guard against an edge-case where there
194195
# are more platforms defined than there are wheels for and users
@@ -208,7 +209,7 @@ def _add_whl_library(self, *, python_version, whl, repo):
208209
))
209210
self._whl_libraries[repo_name] = repo.args
210211

211-
if not self._config.enable_pipstar and "experimental_target_platforms" in repo.args:
212+
if not enable_pipstar and "experimental_target_platforms" in repo.args:
212213
self._whl_libraries[repo_name] |= {
213214
"experimental_target_platforms": sorted({
214215
# TODO @aignas 2025-07-07: this should be solved in a better way
@@ -342,11 +343,11 @@ def _platforms(*, python_version, config):
342343
)
343344
return platforms
344345

345-
def _evaluate_markers(self, pip_attr):
346+
def _evaluate_markers(self, pip_attr, enable_pipstar):
346347
if self._evaluate_markers_fn:
347348
return self._evaluate_markers_fn
348349

349-
if self._config.enable_pipstar:
350+
if enable_pipstar:
350351
return lambda _, requirements: evaluate_markers_star(
351352
requirements = requirements,
352353
platforms = self._platforms[pip_attr.python_version],
@@ -387,13 +388,15 @@ def _create_whl_repos(
387388
self,
388389
module_ctx,
389390
*,
390-
pip_attr):
391+
pip_attr,
392+
enable_pipstar = False):
391393
"""create all of the whl repositories
392394
393395
Args:
394396
self: the builder.
395397
module_ctx: {type}`module_ctx`.
396398
pip_attr: {type}`struct` - the struct that comes from the tag class iteration.
399+
enable_pipstar: {type}`bool` - enable the pipstar or not.
397400
"""
398401
logger = self._logger
399402
platforms = self._platforms[pip_attr.python_version]
@@ -416,7 +419,7 @@ def _create_whl_repos(
416419
platforms = platforms,
417420
extra_pip_args = pip_attr.extra_pip_args,
418421
get_index_urls = self._get_index_urls.get(pip_attr.python_version),
419-
evaluate_markers = _evaluate_markers(self, pip_attr),
422+
evaluate_markers = _evaluate_markers(self, pip_attr, enable_pipstar),
420423
logger = logger,
421424
)
422425

@@ -435,6 +438,7 @@ def _create_whl_repos(
435438
self,
436439
module_ctx,
437440
pip_attr = pip_attr,
441+
enable_pipstar = enable_pipstar,
438442
)
439443
for whl in requirements_by_platform:
440444
whl_library_args = common_args | _whl_library_args(
@@ -452,16 +456,17 @@ def _create_whl_repos(
452456
auth_patterns = self._config.auth_patterns or pip_attr.auth_patterns,
453457
python_version = _major_minor_version(pip_attr.python_version),
454458
is_multiple_versions = whl.is_multiple_versions,
455-
enable_pipstar = self._config.enable_pipstar,
459+
enable_pipstar = enable_pipstar,
456460
)
457461
_add_whl_library(
458462
self,
459463
python_version = pip_attr.python_version,
460464
whl = whl,
461465
repo = repo,
466+
enable_pipstar = enable_pipstar,
462467
)
463468

464-
def _common_args(self, module_ctx, *, pip_attr):
469+
def _common_args(self, module_ctx, *, pip_attr, enable_pipstar):
465470
interpreter = _detect_interpreter(self, pip_attr)
466471

467472
# Construct args separately so that the lock file can be smaller and does not include unused
@@ -481,7 +486,7 @@ def _common_args(self, module_ctx, *, pip_attr):
481486
python_interpreter = interpreter.path,
482487
python_interpreter_target = interpreter.target,
483488
)
484-
if not self._config.enable_pipstar:
489+
if not enable_pipstar:
485490
maybe_args["experimental_target_platforms"] = pip_attr.experimental_target_platforms
486491

487492
whl_library_args.update({k: v for k, v in maybe_args.items() if v})

python/private/pypi/whl_library.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ def _whl_library_impl(rctx):
324324

325325
args = _parse_optional_attrs(rctx, args, extra_pip_args)
326326

327+
# also enable pipstar for any whls that are downloaded without `pip`
328+
enable_pipstar = (rp_config.enable_pipstar or whl_path) and rctx.attr.config_load
327329
if not whl_path:
328330
if rctx.attr.urls:
329331
op_tmpl = "whl_library.BuildWheelFromSource({name}, {requirement})"
@@ -374,7 +376,7 @@ def _whl_library_impl(rctx):
374376
# disable pipstar for that particular case.
375377
#
376378
# Remove non-pipstar and config_load check when we release rules_python 2.
377-
if rp_config.enable_pipstar and rctx.attr.config_load:
379+
if enable_pipstar:
378380
pypi_repo_utils.execute_checked(
379381
rctx,
380382
op = "whl_library.ExtractWheel({}, {})".format(rctx.attr.name, whl_path),

0 commit comments

Comments
 (0)