Skip to content

Transitive dependencies on proto libraries with strip_import_prefix don't work #1557

@tpudlik

Description

@tpudlik

🐞 bug report

Affected Rule

The issue is caused by the rule: py_proto_library

Is this a regression?

No, this was never supported.

Description

If a proto_library A with strip_import_prefix depends on another proto_library B with strip_import_prefix, then the _virtual_imports locations for both A and B must be added to the PYTHONPATH (i.e., to the imports attribute for the generated py_library).

Currently, only the _virtual_imports for A are added to PYTHONPATH.

You can work around this by adding the py_proto_library for B directly to the deps of the py_library that depends on the py_proto_library for A, but it's clearly confusing.

🔬 Minimal Reproduction

This commit adds a unit test that reproduces the issue (as well as a proposed change to py_proto_library.bzl that fixes it): 214bb7c

🔥 Exception or Error


  File "/usr/local/google/home/tpudlik/.cache/bazel/_bazel_tpudlik/1d5247c3691bed961cc8f7244214476e/sandbox/linux-sandbox/210/execroot/rules_python_py_proto_library_example/bazel-out/k8-fastbuild/bin/message_test.runfiles/rules_python_py_proto_library_example/example.com/another_pr
oto/_virtual_imports/message_proto/another_proto/message_pb2.py", line 14, in                                                                                                                                                                                                     
    from proto import pricetag_pb2 as proto_dot_pricetag__pb2                                                                                                                                                                                                                             
ModuleNotFoundError: No module named 'proto'

🌍 Your Environment

Operating System:

  
Linux
  

Output of bazel version:

  
6.2.0
  

Rules_python version:

  
2b05d9fba8cd7406c6c73549885210ba4771cc9e
  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions