@@ -7,11 +7,12 @@ without binding them to a particular version of that package.
77load ("@bazel_skylib//lib:new_sets.bzl" , "sets" )
88load ("@rules_cc//cc/common:cc_info.bzl" , "CcInfo" )
99
10- # rules_python's PyInfo, referenced ONLY in the `deps` provider constraint so
11- # native `@rules_python` targets are still accepted as deps. rules_py emits and
12- # reads its own PyInfo (py_info.bzl).
10+ # rules_python's PyInfo, referenced in the `deps` provider constraint so native
11+ # `@rules_python` targets (e.g. py_proto_library) are accepted as deps. rules_py
12+ # emits its own PyInfo; it reads a dep's sources/imports from either provider via
13+ # the accessors below.
1314load ("@rules_python//python:defs.bzl" , RulesPythonPyInfo = "PyInfo" )
14- load ("//py/private:providers.bzl" , "PyVirtualInfo" , " PyWheelsInfo" )
15+ load ("//py/private:providers.bzl" , "PyWheelsInfo" )
1516load ("//py/private:pth.bzl" , "make_imports_depset" )
1617load ("//py/private:py_info.bzl" , "PyInfo" )
1718
@@ -24,13 +25,15 @@ def _make_instrumented_files_info(ctx):
2425 )
2526
2627def _make_srcs_depset (ctx ):
28+ # `deps` accepts rules_py targets (PyInfo) and native @rules_python targets
29+ # (RulesPythonPyInfo); both expose `transitive_sources`.
2730 return depset (
2831 order = "postorder" ,
2932 direct = ctx .files .srcs ,
3033 transitive = [
31- target [PyInfo ].transitive_sources
34+ ( target [PyInfo ] if PyInfo in target else target [ RulesPythonPyInfo ]) .transitive_sources
3235 for target in ctx .attr .deps
33- if PyInfo in target
36+ if PyInfo in target or RulesPythonPyInfo in target
3437 ],
3538 )
3639
@@ -39,16 +42,17 @@ def _make_virtual_depset(ctx):
3942 order = "postorder" ,
4043 direct = getattr (ctx .attr , "virtual_deps" , []),
4144 transitive = [
42- target [PyVirtualInfo ]. dependencies
45+ target [PyInfo ]. virtual_dependencies
4346 for target in ctx .attr .deps
44- if PyVirtualInfo in target
47+ if PyInfo in target
4548 ],
4649 )
4750
4851def _make_resolved_virtual_depset (target ):
4952 transitive = [target [DefaultInfo ].files ]
50- if PyInfo in target :
51- transitive .append (target [PyInfo ].transitive_sources )
53+ if PyInfo in target or RulesPythonPyInfo in target :
54+ info = target [PyInfo ] if PyInfo in target else target [RulesPythonPyInfo ]
55+ transitive .append (info .transitive_sources )
5256
5357 return depset (
5458 order = "postorder" ,
@@ -63,9 +67,9 @@ def _make_virtual_resolutions_depset(ctx):
6367 for k , v in ctx .attr .resolutions .items ()
6468 ],
6569 transitive = [
66- target [PyVirtualInfo ]. resolutions
70+ target [PyInfo ]. virtual_resolutions
6771 for target in ctx .attr .deps
68- if PyVirtualInfo in target
72+ if PyInfo in target
6973 ],
7074 )
7175
@@ -89,8 +93,9 @@ def _resolve_virtuals(ctx):
8993 v_srcs .append (_make_resolved_virtual_depset (resolution .target ))
9094 v_runfiles .append (resolution .target [DefaultInfo ].default_runfiles .files )
9195
92- if PyInfo in resolution .target :
93- v_imports .append (resolution .target [PyInfo ].imports )
96+ if PyInfo in resolution .target or RulesPythonPyInfo in resolution .target :
97+ info = resolution .target [PyInfo ] if PyInfo in resolution .target else resolution .target [RulesPythonPyInfo ]
98+ v_imports .append (info .imports )
9499
95100 missing = sets .to_list (sets .difference (sets .make (virtual ), sets .make (seen .keys ())))
96101 if len (missing ) > 0 :
@@ -166,10 +171,8 @@ def _py_library_impl(ctx):
166171 PyInfo (
167172 imports = imports ,
168173 transitive_sources = transitive_srcs ,
169- ),
170- PyVirtualInfo (
171- dependencies = virtuals ,
172- resolutions = resolutions ,
174+ virtual_dependencies = virtuals ,
175+ virtual_resolutions = resolutions ,
173176 ),
174177 PyWheelsInfo (
175178 wheels = wheels ,
@@ -184,7 +187,12 @@ _attrs = dict({
184187 ),
185188 "deps" : attr .label_list (
186189 doc = "Targets that produce Python code, commonly `py_library` rules." ,
187- providers = [[PyInfo ], [RulesPythonPyInfo ], [PyVirtualInfo ], [CcInfo ]],
190+ # This attribute — shared by py_library, py_binary and py_test — is the
191+ # public surface that supports rules_python interop: a dep may carry
192+ # rules_py's PyInfo, or native @rules_python's PyInfo (e.g. a
193+ # py_proto_library). RulesPythonPyInfo appears here and at the reads in
194+ # this file for exactly that reason; rules_py never emits it.
195+ providers = [[PyInfo ], [RulesPythonPyInfo ], [CcInfo ]],
188196 ),
189197 "data" : attr .label_list (
190198 doc = """Runtime dependencies of the program.
0 commit comments