Bazel python proto rules overriding "google" module

133 views Asked by At

I encountered an issue with the proto rules provided by rules_python. I believe adding protos that utilizes py_proto_library will overshadow the "google" module, making relevant PIP dependencies unable to be found.

I created a repo with a simple example to demonstrate this. In this example, as long as I do not include proto dependencies(py_proto_library), my app is able to locate the google.protobuf and google.auth modules correctly. However, as soon as I add the proto dependency, I would encounter this issue:

The app code is simple:

import google
print(google.__file__)
import google.protobuf
print(google.protobuf.__file__)
import google.auth
print(google.auth.__file__)

If I have proto dependency, I get this error:

Traceback (most recent call last):
  File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/7e6ecf527bf713b1567f15e2f26950b5/execroot/__main__/bazel-out/k8-fastbuild/bin/app.runfiles/__main__/app.py", line 5, in <module>
    import google.auth
ModuleNotFoundError: No module named 'google.auth'

If I do not have the proto dependencies, the google module is located in

.../pypi_google_auth/site-packages/google/__init__.py

If I switch to include the proto, the google module is in:

.../com_github_protocolbuffers_protobuf/python/google/__init__.py

How can I continue using proto, but also make google.auth accessible? Thank you!

UPDATE: I was able to narrow down the culprit to this change, and verified with a patch. I still don't understand why this is the cause, will spend some time on it.

0

There are 0 answers