Skip to content

Commit e7e4b2c

Browse files
authored
refactor: explicitly declare minimum bazel version of 8.5.0 for the Facts API (#1303)
### Changes are visible to end-users: no ### Test plan - Covered by existing test cases
1 parent 1d445d9 commit e7e4b2c

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module(
44
name = "aspect_rules_py",
5+
bazel_compatibility = [">=8.5.0"],
56
compatibility_level = 1,
67
)
78

py/private/interpreter/extension.bzl

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,9 @@ def _fetch_release_index(module_ctx, release_date, base_url, facts):
155155
return index
156156

157157
def _python_interpreters_impl(module_ctx):
158-
has_facts = hasattr(module_ctx, "facts")
159-
160158
# Facts is a special Bazel type that supports .get() but is not iterable.
161159
# We read from it with .get(key) and build a new dict for output.
162-
facts = module_ctx.facts if has_facts else {}
160+
facts = module_ctx.facts
163161

164162
# Track whether the extension is reproducible. Using "latest" as a release
165163
# date makes it non-reproducible since the resolution depends on when it runs.
@@ -259,7 +257,10 @@ def _python_interpreters_impl(module_ctx):
259257
allow_pre_release[major_minor] = True
260258

261259
if not requested_versions:
262-
return _return_metadata(module_ctx, has_facts, facts, is_reproducible)
260+
return module_ctx.extension_metadata(
261+
facts = facts,
262+
reproducible = is_reproducible,
263+
)
263264

264265
new_facts = {}
265266
release_indices = {}
@@ -368,7 +369,12 @@ def _python_interpreters_impl(module_ctx):
368369
toolchains = toolchain_entries,
369370
)
370371

371-
return _return_metadata(module_ctx, has_facts, new_facts, is_reproducible)
372+
# Non-reproducible means "latest" was used: signal this to Bazel so it
373+
# warns the user and doesn't cache the extension evaluation.
374+
return module_ctx.extension_metadata(
375+
facts = new_facts,
376+
reproducible = is_reproducible,
377+
)
372378

373379
def _find_asset(major_minor, platform, runtime_mode, release_dates, release_indices):
374380
"""Find the best asset across releases, preferring newer releases."""
@@ -385,20 +391,6 @@ def _find_asset(major_minor, platform, runtime_mode, release_dates, release_indi
385391
}
386392
return None
387393

388-
def _return_metadata(module_ctx, has_facts, facts, is_reproducible):
389-
"""Return extension_metadata with facts and reproducibility info.
390-
391-
Non-reproducible means "latest" was used: signal this to Bazel so it
392-
warns the user and doesn't cache the extension evaluation.
393-
"""
394-
if not has_facts or not hasattr(module_ctx, "extension_metadata"):
395-
return None
396-
397-
return module_ctx.extension_metadata(
398-
facts = facts,
399-
reproducible = is_reproducible,
400-
)
401-
402394
_configure_tag = tag_class(
403395
attrs = {
404396
"base_url": attr.string(

0 commit comments

Comments
 (0)