Skip to content

feat(bzlmod): make __init__.py generation configurable module-wide - #3997

Open
armandomontanez wants to merge 7 commits into
bazel-contrib:mainfrom
armandomontanez:legacy-init-migration-configurator
Open

feat(bzlmod): make __init__.py generation configurable module-wide#3997
armandomontanez wants to merge 7 commits into
bazel-contrib:mainfrom
armandomontanez:legacy-init-migration-configurator

Conversation

@armandomontanez

@armandomontanez armandomontanez commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

In #3841, a warning pushing users to migrate away from implicit __init__.py generation was added. While it's good to flag this bad behavior, silencing it requires 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 #2945

@armandomontanez
armandomontanez force-pushed the legacy-init-migration-configurator branch 2 times, most recently from 52ca889 to b98502f Compare August 3, 2026 23:57
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
…_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.
@rickeylev rickeylev changed the title feat: Make __init__.py generation configurable module-wide feat(bzlmod): make __init__.py generation configurable module-wide Aug 11, 2026
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 rickeylev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants