Skip to content

Commit cc46fb2

Browse files
layusrickeylev
andauthored
fix: declare PyInfo as provided by test/binary/library (#2777)
Currently, the rules don't advertise the PyInfo provider through the provides argument to the rule function. This means that aspects that want to consume PyInfo can't use `required_providers` to restrict themselves to the Python rules, and instead have to apply to all rules. To fix, add PyInfo to the provides arg of the rules. Fixes #2506 --------- Co-authored-by: Richard Levasseur <[email protected]> Co-authored-by: Richard Levasseur <[email protected]>
1 parent 844e7ad commit cc46fb2

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

+22
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ BEGIN_UNRELEASED_TEMPLATE
4747
END_UNRELEASED_TEMPLATE
4848
-->
4949

50+
{#v0-0-0}
51+
## Unreleased
52+
53+
[0.0.0]: https://github.com/bazel-contrib/rules_python/releases/tag/0.0.0
54+
55+
{#v0-0-0-changed}
56+
### Changed
57+
* Nothing changed.
58+
59+
{#v0-0-0-fixed}
60+
### Fixed
61+
* (rules) PyInfo provider is now advertised by py_test, py_binary, and py_library;
62+
this allows aspects using required_providers to function correctly.
63+
([#2506](https://github.com/bazel-contrib/rules_python/issues/2506)).
64+
65+
{#v0-0-0-added}
66+
### Added
67+
* Nothing added.
68+
69+
{#v0-0-0-removed}
70+
### Removed
71+
* Nothing removed.
5072

5173
{#1-4-0}
5274
## [1.4.0] - 2025-04-19

python/private/py_executable.bzl

+3-1
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,8 @@ def create_base_executable_rule():
18541854
"""
18551855
return create_executable_rule_builder().build()
18561856

1857+
_MaybeBuiltinPyInfo = [BuiltinPyInfo] if BuiltinPyInfo != None else []
1858+
18571859
# NOTE: Exported publicly
18581860
def create_executable_rule_builder(implementation, **kwargs):
18591861
"""Create a rule builder for an executable Python program.
@@ -1877,7 +1879,7 @@ def create_executable_rule_builder(implementation, **kwargs):
18771879
attrs = EXECUTABLE_ATTRS,
18781880
exec_groups = dict(REQUIRED_EXEC_GROUP_BUILDERS), # Mutable copy
18791881
fragments = ["py", "bazel_py"],
1880-
provides = [PyExecutableInfo],
1882+
provides = [PyExecutableInfo, PyInfo] + _MaybeBuiltinPyInfo,
18811883
toolchains = [
18821884
ruleb.ToolchainType(TOOLCHAIN_TYPE),
18831885
ruleb.ToolchainType(EXEC_TOOLS_TOOLCHAIN_TYPE, mandatory = False),

python/private/py_library.bzl

+5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ load(
4343
load(":flags.bzl", "AddSrcsToRunfilesFlag", "PrecompileFlag", "VenvsSitePackages")
4444
load(":precompile.bzl", "maybe_precompile")
4545
load(":py_cc_link_params_info.bzl", "PyCcLinkParamsInfo")
46+
load(":py_info.bzl", "PyInfo")
4647
load(":py_internal.bzl", "py_internal")
48+
load(":reexports.bzl", "BuiltinPyInfo")
4749
load(":rule_builders.bzl", "ruleb")
4850
load(
4951
":toolchain_types.bzl",
@@ -299,6 +301,8 @@ def _repo_relative_short_path(short_path):
299301
else:
300302
return short_path
301303

304+
_MaybeBuiltinPyInfo = [BuiltinPyInfo] if BuiltinPyInfo != None else []
305+
302306
# NOTE: Exported publicaly
303307
def create_py_library_rule_builder():
304308
"""Create a rule builder for a py_library.
@@ -319,6 +323,7 @@ def create_py_library_rule_builder():
319323
exec_groups = dict(REQUIRED_EXEC_GROUP_BUILDERS),
320324
attrs = LIBRARY_ATTRS,
321325
fragments = ["py"],
326+
provides = [PyCcLinkParamsInfo, PyInfo] + _MaybeBuiltinPyInfo,
322327
toolchains = [
323328
ruleb.ToolchainType(TOOLCHAIN_TYPE, mandatory = False),
324329
ruleb.ToolchainType(EXEC_TOOLS_TOOLCHAIN_TYPE, mandatory = False),

0 commit comments

Comments
 (0)