Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py_proto_library overriding "google" module #1338

Closed
yechuan51 opened this issue Jul 23, 2023 · 3 comments
Closed

py_proto_library overriding "google" module #1338

yechuan51 opened this issue Jul 23, 2023 · 3 comments
Labels
Can Close? Will close in 30 days if there is no new activity

Comments

@yechuan51
Copy link

🐞 bug report

Affected Rule

The issue is caused by the rule:

py_proto_library

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

Unable to verify.

Description

A clear and concise description of the problem...

I realized an issue yesterday that many of the PIP dependencies cannot be used because of ModuleNotFoundError. I investigated a bit and found out that they are all "google.xxx" modules.

My investigation has led me here, I believe the implementation of py_proto_library might have caused all "import google.xxx" to be directed to a runfile path with just "google.protobuf".

🔬 Minimal Reproduction

I created a PR on a forked version of this repo:
yechuan51/rules_python_overriding_module#1

In additon, I have created a repo from scratch that reproduces this error:
https://github.com/yechuan51/proto_rule_overshadow

🔥 Exception or Error





/home/ubuntu/.cache/bazel/_bazel_ubuntu/9b2305b6489efaf56c30b637b3658310/execroot/rules_python_pip_parse_example/bazel-out/k8-fastbuild/bin/main.runfiles/com_github_protocolbuffers_protobuf/python/google/__init__.py
['/home/ubuntu/.cache/bazel/_bazel_ubuntu/9b2305b6489efaf56c30b637b3658310/execroot/rules_python_pip_parse_example/bazel-out/k8-fastbuild/bin/main.runfiles/com_github_protocolbuffers_protobuf/python/google']
/home/ubuntu/.cache/bazel/_bazel_ubuntu/9b2305b6489efaf56c30b637b3658310/execroot/rules_python_pip_parse_example/bazel-out/k8-fastbuild/bin/main.runfiles/com_github_protocolbuffers_protobuf/python/google/protobuf/__init__.py
Traceback (most recent call last):
  File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/9b2305b6489efaf56c30b637b3658310/execroot/rules_python_pip_parse_example/bazel-out/k8-fastbuild/bin/main.runfiles/rules_python_pip_parse_example/main.py", line 20, in 
    import google.auth
ModuleNotFoundError: No module named 'google.auth'

🌍 Your Environment

Operating System:

  
  Ubuntu 22.04
  

Output of bazel version:

  
   6.2.1
  

Rules_python version:

  
0.24.0
  

Anything else relevant?
I asked the same question on Stackoverflow:
https://stackoverflow.com/questions/76746080/bazel-python-proto-rules-overriding-google-module

@yechuan51
Copy link
Author

yechuan51 commented Jul 23, 2023

Update:

After more time spent, I was lucky enough to find a version of the rules_python that doesn't have this issue. After much regression testing, I found the change that introduced this issue:
6905e63

I'm also able to create a patch to verify the issue is isolated within python/private/proto/py_proto_library.bzl.
https://github.com/yechuan51/proto_rule_overshadow/pull/1/files#diff-fd5c780a055d4828faa880b41d8f83a5fbee051650b0675273a44e7d5a77469e

@aignas @rickeylev can you please take a look and see if this change might have caused this unintended behaviour? Thank you!

@aignas
Copy link
Collaborator

aignas commented Sep 14, 2023

As per this slack thread the solution would be to disable the deprecated (bazelbuild/bazel#7386) feature to create __init__.py files by default by using https://bazel.build/reference/command-line-reference#flag--incompatible_default_to_explicit_init_py.

If this works please close the issue.

@aignas aignas added the Can Close? Will close in 30 days if there is no new activity label Sep 20, 2023
@github-actions
Copy link

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Can Close? Will close in 30 days if there is no new activity
Projects
None yet
Development

No branches or pull requests

2 participants