@@ -378,6 +378,7 @@ def create_py_info(
378378 implicit_pyc_files ,
379379 implicit_pyc_source_files ,
380380 imports ,
381+ package = None ,
381382 venv_symlinks = []):
382383 """Create PyInfo provider.
383384
@@ -396,6 +397,7 @@ def create_py_info(
396397 implicit_pyc_files: {type}`depset[File]` Implicitly generated pyc files
397398 that a binary can choose to include.
398399 imports: depset of strings; the import path values to propagate.
400+ package: TODO
399401 venv_symlinks: {type}`list[VenvSymlinkEntry]` instances for
400402 symlinks to create in the consuming binary's venv.
401403
@@ -418,9 +420,15 @@ def create_py_info(
418420 py_info .merge_has_py2_only_sources (ctx .attr .srcs_version in ("PY2" , "PY2ONLY" ))
419421 py_info .merge_has_py3_only_sources (ctx .attr .srcs_version in ("PY3" , "PY3ONLY" ))
420422
423+ # First merge the third party deps
424+ # TODO @aignas 2025-06-05: refactor the code
425+
421426 for target in ctx .attr .deps :
422427 # PyInfo may not be present e.g. cc_library rules.
423428 if PyInfo in target or (BuiltinPyInfo != None and BuiltinPyInfo in target ):
429+ if not target [PyInfo ].package :
430+ continue
431+
424432 py_info .merge (_get_py_info (target ))
425433 else :
426434 # TODO(b/228692666): Remove this once non-PyInfo targets are no
@@ -433,6 +441,34 @@ def create_py_info(
433441 for target in ctx .attr .pyi_deps :
434442 # PyInfo may not be present e.g. cc_library rules.
435443 if PyInfo in target or (BuiltinPyInfo != None and BuiltinPyInfo in target ):
444+ if not target [PyInfo ].package :
445+ continue
446+
447+ py_info .merge (_get_py_info (target ))
448+
449+ # Now proceed with the first party deps
450+
451+ for target in ctx .attr .deps :
452+ # PyInfo may not be present e.g. cc_library rules.
453+ if PyInfo in target or (BuiltinPyInfo != None and BuiltinPyInfo in target ):
454+ if target [PyInfo ].package :
455+ continue
456+
457+ py_info .merge (_get_py_info (target ))
458+ else :
459+ # TODO(b/228692666): Remove this once non-PyInfo targets are no
460+ # longer supported in `deps`.
461+ files = target .files .to_list ()
462+ for f in files :
463+ if f .extension == "py" :
464+ py_info .transitive_sources .add (f )
465+ py_info .merge_uses_shared_libraries (cc_helper .is_valid_shared_library_artifact (f ))
466+ for target in ctx .attr .pyi_deps :
467+ # PyInfo may not be present e.g. cc_library rules.
468+ if PyInfo in target or (BuiltinPyInfo != None and BuiltinPyInfo in target ):
469+ if target [PyInfo ].package :
470+ continue
471+
436472 py_info .merge (_get_py_info (target ))
437473
438474 deps_transitive_sources = py_info .transitive_sources .build ()
@@ -457,7 +493,7 @@ def create_py_info(
457493 if py_info .get_uses_shared_libraries ():
458494 break
459495
460- return py_info .build (), deps_transitive_sources , py_info .build_builtin_py_info ()
496+ return py_info .build (package ), deps_transitive_sources , py_info .build_builtin_py_info ()
461497
462498def _get_py_info (target ):
463499 return target [PyInfo ] if PyInfo in target or BuiltinPyInfo == None else target [BuiltinPyInfo ]
0 commit comments