Skip to content

fix implicit __init__.py creation warnings - #1097

Merged
aiuto merged 1 commit into
bazelbuild:mainfrom
dws:diabolic
Nov 18, 2026
Merged

aiuto merged 1 commit into
bazelbuild:mainfrom
dws:diabolic

Conversation

@dws

@dws dws commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

We here avoid diagnostics such as the following without resorting to the Bazel flag --incompatible_default_to_explicit_init_py, which is deprecated as of Bazel 10:

======================================================================
WARNING: Target @@rules_pkg+//pkg/private/deb:make_deb is using implicit __init__.py creation.
  This diabolic behavior is deprecated and will be disabled by default in a
  future release.
  See https://github.com/bazel-contrib/rules_python/issues/2945

  Ensure all __init__.py files are explicitly created and
  added to the srcs or deps of your targets.

  Disable implicit creation for your module in MODULE.bazel:

    rules_python_config = use_extension("@rules_python//python/extensions:config.bzl", "config")
    rules_python_config.explicit_init_py(default = True)

  Or for a specific target by setting:

    legacy_create_init = 0

  Or globally with the following Bazel flag:

    --incompatible_default_to_explicit_init_py
======================================================================

I saw these diagnostics with rules_python 2.5.0-rc3 and Bazel 9.3.2 (without the flag --incompatible_default_to_explicit_init_py).

Note that legacy_create_init = 0 is supported in rules_python 1.7.0, so there's no need to bump the minimum version of rules_python required by rules_pkg. The explicit_init_py() method first appeared in rules_python 2.3.0, so using it to deal with these warnings would require bumping the minimum version of rules_python. I applied the legacy_create_init = 0 as follows:

buildozer "set legacy_create_init 0" //...:%py_binary
buildozer "set legacy_create_init 0" //...:%py_test

Fixed up pkg/install.bzl by hand per review comment from @fmeum.

@dws
dws marked this pull request as ready for review November 10, 2026 22:34
@fmeum

fmeum commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for this! One spot that buildozer can't reach since it's created by a macro: the py_binary generated by pkg_install in pkg/install.bzl also doesn't set legacy_create_init, so users of pkg_install will still see the rules_python warning for their own targets:

    py_binary(
        name = name,
        srcs = [":" + name + "_install_script"],
        main = name + "_install_script.py",
        deps = [Label("//pkg/private:manifest"), Label("@rules_python//python/runfiles")],
        legacy_create_init = 0,
        srcs_version = "PY3",
        python_version = "PY3",
        **kwargs
    )

Would you mind adding legacy_create_init = 0 there as well?

@dws

dws commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Would you mind adding legacy_create_init = 0 there as well?

Happy to!

We here avoid diagnostics such as the following without resorting to
the Bazel flag `--incompatible_default_to_explicit_init_py`, which is
deprecated as of Bazel 10:

    ======================================================================
    WARNING: Target @@rules_pkg+//pkg/private/deb:make_deb is using implicit __init__.py creation.
      This diabolic behavior is deprecated and will be disabled by default in a
      future release.
      See bazel-contrib/rules_python#2945

      Ensure all __init__.py files are explicitly created and
      added to the srcs or deps of your targets.

      Disable implicit creation for your module in MODULE.bazel:

        rules_python_config = use_extension("@rules_python//python/extensions:config.bzl", "config")
        rules_python_config.explicit_init_py(default = True)

      Or for a specific target by setting:

        legacy_create_init = 0

      Or globally with the following Bazel flag:

        --incompatible_default_to_explicit_init_py
    ======================================================================

I saw these diagnostics with rules_python 2.5.0-rc3 and Bazel 9.3.2
(without the flag `--incompatible_default_to_explicit_init_py`).

Note that `legacy_create_init = 0` is supported in rules_python 1.7.0,
so there's no need to bump the minimum version of rules_python required
by rules_pkg.  The `explicit_init_py()` method first appeared in
rules_python 2.3.0, so using it to deal with these warnings would
require bumping the minimum version of rules_python.  I applied the
`legacy_create_init = 0` as follows:

    buildozer "set legacy_create_init 0" //...:%py_binary
    buildozer "set legacy_create_init 0" //...:%py_test

Fixed up pkg/install.bzl by hand per review comment from @fmeum.
@dws

dws commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Would you mind adding legacy_create_init = 0 there as well?

Done!

@dws

dws commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

@fmeum What more must be done to get this to land?

@fmeum

fmeum commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Not sure, I can't merge here.

@cgrindel @aiuto

@cgrindel

Copy link
Copy Markdown
Collaborator

@aiuto Did you want to take a look before we merge?

copybara-service Bot pushed a commit to bazelbuild/bazel that referenced this pull request Nov 17, 2026
Fixes the Bazel-side warnings printed by `bazel build --config=llvm //src:bazel-dev` on a clean output base:

* Replace the `--cpu`-based `config_setting`s in `//src/conditions`, which trigger a deprecation warning (`select() on cpu is deprecated`), with the existing constraint-based ones. Bazel CI doesn't use `--cpu` anymore.
* Set `legacy_create_init = 0` on Bazel's own `py_binary` targets (`//src:create_embedded_tools`, `//tools/build_defs/proguard:wrapper_private`) to address the rules_python implicit `__init__.py` deprecation.
* Drop the explicit `jar` packaging from Maven coordinates (`Assuming ... should be interpreted as ...`) and declare `known_contributing_modules` for the `maven` repo. `maven_install.json` only changes its input hash.
* Only pass the `java_proto_library` for the service to `java_grpc_library`, as multiple `deps` are deprecated. The longrunning protos are covered transitively.
* Exclude incubator modules from the "all modules" embedded JDK, which jlink warns about (`Using incubator modules: jdk.incubator.vector`) and Bazel doesn't use.

Remaining warnings are fixed elsewhere and will be picked up by follow-up dependency updates:

* c-ares: #32649 (drop c-ares), bazelbuild/bazel-central-registry#11756
* zstd-jni: bazelbuild/bazel-central-registry#11757 (zstd-jni 1.5.7-26)
* protobuf: deprecated `GetEnum`/`GetRepeatedEnum` calls are fixed in protobuf 37.0
* rules_pkg: bazelbuild/rules_pkg#1097
* gRPC: grpc/grpc#43933, grpc/grpc-java#13188
* Mirror: #32646

Closes #32651

COPYBARA_INTEGRATE_REVIEW=#32651 from fmeum:fix-build-warnings 5f5e9c3
PiperOrigin-RevId: 1023592606
Change-Id: Ia04594ff9c771f596c291bf0d4785915124c6a5a

@aiuto aiuto 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.

I still think it's completely ridiculous that we need to put this legacy_init stuff on targets that actually have init.py. But that's the way rules python works, so resistance is futile.

@aiuto
aiuto merged commit beb7bfc into bazelbuild:main Nov 18, 2026
6 checks passed
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.

4 participants