include python/google/__init__.py to python_srcs for bazel rules
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
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:
- Delete
google/__init__.pyentirely. - Set legacy_create_init to
0, so an__init__.pyis not implicitly created.
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
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?
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?
stripping the path by one level should not cause any issue right?
It should not.
But since it just one file,
__init__.pycan be explicitly listed in srcs instead of modifying glob().WDYT?
Sure. Have you tried that though?
Sorry for the slow review on this. Is it still an issue?
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
Rebased PR on top of HEAD
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.
I think you need a rebase once more.
Done
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.
I would still prefer to just delete __init__.py if that will work.