@@ -6,15 +6,10 @@ without binding them to a particular version of that package.
66
77load ("@bazel_skylib//lib:new_sets.bzl" , "sets" )
88load ("@rules_cc//cc/common:cc_info.bzl" , "CcInfo" )
9-
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.
14- load ("@rules_python//python:defs.bzl" , RulesPythonPyInfo = "PyInfo" )
159load ("//py/private:providers.bzl" , "PyWheelsInfo" )
1610load ("//py/private:pth.bzl" , "make_imports_depset" )
1711load ("//py/private:py_info.bzl" , "PyInfo" )
12+ load ("//py/private:py_info_interop.bzl" , "RulesPythonPyInfo" , "get_py_info" , "has_py_info" )
1813
1914def _make_instrumented_files_info (ctx ):
2015 return coverage_common .instrumented_files_info (
@@ -25,15 +20,15 @@ def _make_instrumented_files_info(ctx):
2520 )
2621
2722def _make_srcs_depset (ctx ):
28- # `deps` accepts rules_py targets ( PyInfo) and native @rules_python targets
29- # (RulesPythonPyInfo); both expose `transitive_sources`.
23+ # `deps` may carry rules_py's PyInfo or native @rules_python's; both expose
24+ # `transitive_sources`. See py_info_interop.bzl .
3025 return depset (
3126 order = "postorder" ,
3227 direct = ctx .files .srcs ,
3328 transitive = [
34- (target [ PyInfo ] if PyInfo in target else target [ RulesPythonPyInfo ] ).transitive_sources
29+ get_py_info (target ).transitive_sources
3530 for target in ctx .attr .deps
36- if PyInfo in target or RulesPythonPyInfo in target
31+ if has_py_info ( target )
3732 ],
3833 )
3934
@@ -50,8 +45,8 @@ def _make_virtual_depset(ctx):
5045
5146def _make_resolved_virtual_depset (target ):
5247 transitive = [target [DefaultInfo ].files ]
53- if PyInfo in target or RulesPythonPyInfo in target :
54- info = target [ PyInfo ] if PyInfo in target else target [ RulesPythonPyInfo ]
48+ info = get_py_info ( target )
49+ if info :
5550 transitive .append (info .transitive_sources )
5651
5752 return depset (
@@ -93,8 +88,8 @@ def _resolve_virtuals(ctx):
9388 v_srcs .append (_make_resolved_virtual_depset (resolution .target ))
9489 v_runfiles .append (resolution .target [DefaultInfo ].default_runfiles .files )
9590
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 ]
91+ info = get_py_info ( resolution .target )
92+ if info :
9893 v_imports .append (info .imports )
9994
10095 missing = sets .to_list (sets .difference (sets .make (virtual ), sets .make (seen .keys ())))
@@ -190,8 +185,8 @@ _attrs = dict({
190185 # This attribute — shared by py_library, py_binary and py_test — is the
191186 # public surface that supports rules_python interop: a dep may carry
192187 # 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 .
188+ # py_proto_library). Reads go through py_info_interop.bzl's accessors;
189+ # rules_py never emits RulesPythonPyInfo .
195190 providers = [[PyInfo ], [RulesPythonPyInfo ], [CcInfo ]],
196191 ),
197192 "data" : attr .label_list (
0 commit comments