fix implicit __init__.py creation warnings (#1097)

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.
19 files changed
tree: c03d5dd0392096ecea69f75578b4a2a7a2fe0d1c
  1. .agents/
  2. .bazelci/
  3. .bcr/
  4. .claude/
  5. .github/
  6. contrib/
  7. distro/
  8. doc_build/
  9. docs/
  10. examples/
  11. pkg/
  12. providers/
  13. tests/
  14. toolchains/
  15. .bazelignore
  16. .bazelrc
  17. .gitignore
  18. .pre-commit-config.yaml
  19. .typos.toml
  20. AGENTS.md
  21. AUTHORS
  22. BUILD
  23. CHANGELOG.md
  24. CLAUDE.md
  25. CODEOWNERS
  26. CONTRIBUTING.md
  27. CONTRIBUTORS
  28. deps.bzl
  29. developers.md
  30. GEMINI.md
  31. LICENSE
  32. mappings.bzl
  33. MODULE.bazel
  34. patching.md
  35. pkg.bzl
  36. README.md
  37. version.bzl
  38. WORKSPACE
  39. WORKSPACE.bzlmod
README.md

Bazel package building

Bazel rules for building tar, zip, deb, and rpm for packages.

For the latest version, see Releases (with WORKSPACE setup) / Documentation

Use rules-pkg-discuss@googlegroups.com for discussion.

CI: Build status

Basic rules

Package building rules

  • pkg - Rules for building packages of various types.
  • examples - Cookbook examples for using the rules.

As of Bazel 4.x, Bazel uses this rule set for packaging its distribution. Bazel still contains a limited version of pkg_tar but its feature set is frozen. Any new capabilities will be added here.

WORKSPACE setup

Sample, but see releases for the current release.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_pkg",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
        "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
    ],
    sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
)
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()

To use pkg_rpm(), you must provide a copy of rpmbuild. You can use the system installed rpmbuild with this stanza.

load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild")

find_system_rpmbuild(
    name = "rules_pkg_rpmbuild",
    verbose = False,
)

MODULE.bazel setup

bazel_dep(name = "rules_pkg", version = "0.0.10")

To use pkg_rpm(), you must provide a copy of rpmbuild. You can use the system installed rpmbuild with this stanza.

find_rpm = use_extension("//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild_bzlmod")
use_repo(find_rpm, "rules_pkg_rpmbuild")
register_toolchains("@rules_pkg_rpmbuild//:all")

For developers

We hold an engineering status meeting on the first Monday of every month at 10am USA East coast time. Add to calendar / meeting notes