Skip to content

Commit 825acde

Browse files
authored
fix: make versioned rules return both builtin and rules_python providers (#2116)
This makes the versioned rules return both the `@builtin` and `@rules_python` provider objects. This makes the versioned rules more compatible with the non-versioned rules. Fixes #2114
1 parent 3b183bf commit 825acde

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ A brief description of the categories of changes:
4545
* (rules) User dependencies come before runtime site-packages when using
4646
{obj}`--bootstrap_impl=script`.
4747
([#2064](https://github.com/bazelbuild/rules_python/issues/2064)).
48+
* (rules) Version-aware rules now return both `@_builtins` and `@rules_python`
49+
providers instead of only one.
50+
([#2114](https://github.com/bazelbuild/rules_python/issues/2114)).
4851
* (pip) Fixed pypi parse_simpleapi_html function for feeds with package metadata
4952
containing ">" sign
5053
* (toolchains) Added missing executable permission to

python/config_settings/transition.bzl

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,12 @@ def _transition_py_impl(ctx):
8181
for k, v in ctx.attr.env.items():
8282
env[k] = ctx.expand_location(v)
8383

84-
if PyInfo in target:
85-
py_info = target[PyInfo]
86-
elif BuiltinPyInfo in target:
87-
py_info = target[BuiltinPyInfo]
88-
else:
89-
fail("target {} does not have rules_python PyInfo or builtin PyInfo".format(target))
90-
91-
if PyRuntimeInfo in target:
92-
py_runtime_info = target[PyRuntimeInfo]
93-
elif BuiltinPyRuntimeInfo in target:
94-
py_runtime_info = target[BuiltinPyRuntimeInfo]
95-
else:
96-
fail(
97-
"target {} does not have rules_python PyRuntimeInfo or builtin PyRuntimeInfo. ".format(target) +
98-
"There is likely no toolchain being matched to your configuration, use --toolchain_resolution_debug parameter to get more information",
99-
)
100-
10184
providers = [
10285
DefaultInfo(
10386
executable = executable,
10487
files = depset(default_outputs, transitive = [target[DefaultInfo].files]),
10588
runfiles = ctx.runfiles(default_outputs).merge(target[DefaultInfo].default_runfiles),
10689
),
107-
py_info,
108-
py_runtime_info,
10990
# Ensure that the binary we're wrapping is included in code coverage.
11091
coverage_common.instrumented_files_info(
11192
ctx,
@@ -118,6 +99,15 @@ def _transition_py_impl(ctx):
11899
# https://github.com/bazelbuild/bazel/commit/dbdfa07e92f99497be9c14265611ad2920161483
119100
testing.TestEnvironment(env),
120101
]
102+
if PyInfo in target:
103+
providers.append(target[PyInfo])
104+
if BuiltinPyInfo in target and PyInfo != BuiltinPyInfo:
105+
providers.append(target[BuiltinPyInfo])
106+
107+
if PyRuntimeInfo in target:
108+
providers.append(target[PyRuntimeInfo])
109+
if BuiltinPyRuntimeInfo in target and PyRuntimeInfo != BuiltinPyRuntimeInfo:
110+
providers.append(target[BuiltinPyRuntimeInfo])
121111
return providers
122112

123113
_COMMON_ATTRS = {

tests/config_settings/transition/multi_version_tests.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
1717
load("@rules_testing//lib:test_suite.bzl", "test_suite")
1818
load("@rules_testing//lib:util.bzl", "TestingAspectInfo", rt_util = "util")
19+
load("//python:py_info.bzl", "PyInfo")
1920
load("//python/config_settings:transition.bzl", py_binary_transitioned = "py_binary", py_test_transitioned = "py_test")
21+
load("//python/private:reexports.bzl", "BuiltinPyInfo") # buildifier: disable=bzl-visibility
2022
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
2123

2224
# NOTE @aignas 2024-06-04: we are using here something that is registered in the MODULE.Bazel
@@ -45,7 +47,8 @@ def _test_py_test_with_transition(name):
4547

4648
def _test_py_test_with_transition_impl(env, target):
4749
# Nothing to assert; we just want to make sure it builds
48-
_ = env, target # @unused
50+
env.expect.that_target(target).has_provider(PyInfo)
51+
env.expect.that_target(target).has_provider(BuiltinPyInfo)
4952

5053
_tests.append(_test_py_test_with_transition)
5154

@@ -65,7 +68,8 @@ def _test_py_binary_with_transition(name):
6568

6669
def _test_py_binary_with_transition_impl(env, target):
6770
# Nothing to assert; we just want to make sure it builds
68-
_ = env, target # @unused
71+
env.expect.that_target(target).has_provider(PyInfo)
72+
env.expect.that_target(target).has_provider(BuiltinPyInfo)
6973

7074
_tests.append(_test_py_binary_with_transition)
7175

0 commit comments

Comments
 (0)