protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

include python/google/__init__.py to python_srcs for bazel rules

Open Zaspire opened this issue 3 years ago • 13 comments

google.* python's name space is shared between packages(e.g. google.oauth2, google.cloud ...) pkg_resources magic required in all google/init.py files for it to work.

if src/google/init.py is not included, bazel will generate an empty init.py. which breaks import of other modules, in case protobuf included as bazel dependency

Zaspire avatar Apr 20 '22 22:04 Zaspire

pkg_resources magic required in all google/init.py files for it to work.

Since PEP 420, it is no longer necessary to use pkg_resources magic to create a namespace package. Instead we can just omit __init__.py to get namespace package behavior.

Could we instead:

  1. Delete google/__init__.py entirely.
  2. Set legacy_create_init to 0, so an __init__.py is not implicitly created.

haberman avatar Apr 22 '22 07:04 haberman

Delete google/init.py entirely

this does work.

Set legacy_create_init to 0

legacy_create_init is not available for py_library

Only for py_binary and py_test. This way, legacy_create_init will need to be set on each binary and test that transitively depends on protobuf

Zaspire avatar Apr 23 '22 05:04 Zaspire

This should work:

--- a/BUILD
+++ b/BUILD
@@ -864,7 +864,7 @@ py_library(
     name = "python_srcs",
     srcs = glob(
         [
-            "python/google/protobuf/**/*.py",
+            "python/google/**/*.py",
         ],
         exclude = [
             "python/google/protobuf/internal/*_test.py",

Since there is only __init__.py under python/google, stripping the path by one level should not cause any issue right?

Kiyo5hi avatar May 09 '22 07:05 Kiyo5hi

stripping the path by one level should not cause any issue right?

It should not.

But since it just one file, __init__.py can be explicitly listed in srcs instead of modifying glob().

WDYT?

Zaspire avatar May 12 '22 20:05 Zaspire

stripping the path by one level should not cause any issue right?

It should not.

But since it just one file, __init__.py can be explicitly listed in srcs instead of modifying glob().

WDYT?

Sure. Have you tried that though?

Kiyo5hi avatar May 15 '22 07:05 Kiyo5hi

Sorry for the slow review on this. Is it still an issue?

haberman avatar Jul 12 '22 23:07 haberman

Have you tried that though?

yes. Both works fine

Sorry for the slow review on this. Is it still an issue?

yes. I updated PR to latest HEAD

Zaspire avatar Jul 28 '22 04:07 Zaspire

Rebased PR on top of HEAD

Zaspire avatar Aug 24 '22 03:08 Zaspire

I'm really sorry about the delays on this. I think you need a rebase once more. If you can do that and the tests pass I can get this in this week.

deannagarcia avatar Oct 03 '22 21:10 deannagarcia

I think you need a rebase once more.

Done

Zaspire avatar Oct 04 '22 00:10 Zaspire

We triage inactive PRs and issues in order to make it easier to find active work. If this PR should remain active, please add a comment.

This PR is labeled inactive because the last activity was over 90 days ago. This PR will be closed and archived after 14 additional days without activity.

github-actions[bot] avatar Jan 21 '24 10:01 github-actions[bot]

I would still prefer to just delete __init__.py if that will work.

haberman avatar Feb 03 '24 18:02 haberman