feat(bzlmod): make __init__.py generation configurable module-wide - #3997
Merged
rickeylev merged 7 commits intoAug 11, 2026
Merged
Conversation
armandomontanez
force-pushed
the
legacy-init-migration-configurator
branch
2 times, most recently
from
August 3, 2026 23:57
52ca889 to
b98502f
Compare
In bazel-contrib#3841, a warning pushing users to migrate away from implicit `__init__.py` generation was added. While this is very nice to have, it forces users to either explicitly configure this option on every `py_binary` and `py_test` target, or configure the option globally in their `.bazelrc`. To better facilitate a migration, this change introduces a mechanism for modules to configure this option module-wide. This has multiple benefits: 1. Everyone working in the module doesn't need to remember to explicitly set `legacy_create_init` on every target. 2. Everyone that depends on the module receives the correct behavior as configured by the module. 3. It becomes possible to tell BCR-wide which modules have adopted this migration. Work towards bazel-contrib#2945
armandomontanez
force-pushed
the
legacy-init-migration-configurator
branch
from
August 4, 2026 00:01
b98502f to
117b6cb
Compare
This was referenced Aug 4, 2026
…_testing Use mod.is_root directly instead of assuming module iteration order in the config extension to reliably detect the root module. Also migrate explicit_init_py_test from bazel_skylib analysistest to rules_testing.
Rename the use_explicit_init_py tag class on the config extension to explicit_init_py and change its enabled attribute to default. Update all usages, docstrings, and warning messages accordingly.
Add news entry fragment for module-wide explicit __init__.py configuration, version directives in Starlark docstrings, and clean up repository rule parameter naming.
…t init options Update the implicit __init__.py deprecation warning message to clearly list module-wide configuration via config.explicit_init_py, per-target overrides, and the global flag.
rickeylev
approved these changes
Aug 11, 2026
rickeylev
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for this! Overall this was pretty good. I cleaned it up a bit and renamed the api to explicit_init_py(default=...).
Remove cross-repository dependency on @rules_python//tests/support in examples/bzlmod/tests/BUILD.bazel to prevent missing dev-dependency errors when downstream BCR tests build examples.
Contributor
Author
|
Thanks for ushering this in! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In #3841, a warning pushing users to migrate away from implicit
__init__.pygeneration was added. While it's good to flag this bad behavior, silencing it requires users to either explicitly configure this option on everypy_binaryandpy_testtarget, or configure the option globally in their.bazelrc.To better facilitate a migration, this change introduces a mechanism for modules to configure this option module-wide. This has multiple benefits:
legacy_create_initon every target.Work towards #2945