From 9070338cf61d957797e0ae4fb383dff575f4f35c Mon Sep 17 00:00:00 2001 From: David Sanderson <32687193+dws@users.noreply.github.com> Date: Tue, 10 Nov 2026 17:26:32 -0500 Subject: [PATCH] fix implicit __init__.py creation warnings 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. --- distro/BUILD | 1 + doc_build/BUILD | 1 + pkg/BUILD | 2 ++ pkg/install.bzl | 1 + pkg/private/deb/BUILD | 1 + pkg/private/tar/BUILD | 1 + pkg/private/zip/BUILD | 1 + pkg/releasing/BUILD | 3 +++ pkg/rpm/BUILD | 1 + tests/BUILD | 4 ++++ tests/deb/BUILD | 3 +++ tests/install/BUILD | 1 + tests/mappings/filter_directory/BUILD | 1 + tests/rpm/BUILD | 2 ++ tests/rpm/source_date_epoch/BUILD | 2 ++ tests/rpm/tree_artifacts/BUILD | 3 +++ tests/tar/BUILD | 4 ++++ tests/util/BUILD | 2 ++ tests/zip/BUILD | 4 ++++ 19 files changed, 38 insertions(+) diff --git a/distro/BUILD b/distro/BUILD index aa0862fd..95c86437 100644 --- a/distro/BUILD +++ b/distro/BUILD @@ -102,6 +102,7 @@ py_test( ], env_inherit = ["PATH"], imports = [".."], + legacy_create_init = 0, local = True, python_version = "PY3", tags = [ diff --git a/doc_build/BUILD b/doc_build/BUILD index b144f5a8..2f5c4f0c 100644 --- a/doc_build/BUILD +++ b/doc_build/BUILD @@ -123,6 +123,7 @@ stardoc( py_binary( name = "merge", srcs = ["merge.py"], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", visibility = ["//visibility:private"], diff --git a/pkg/BUILD b/pkg/BUILD index 344465d5..2e3540eb 100644 --- a/pkg/BUILD +++ b/pkg/BUILD @@ -75,6 +75,7 @@ py_binary( "make_rpm.py", ], imports = [".."], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", target_compatible_with = select({ @@ -110,6 +111,7 @@ py_binary( "__init__.py", "filter_directory.py", ], + legacy_create_init = 0, python_version = "PY3", visibility = ["//visibility:public"], ) diff --git a/pkg/install.bzl b/pkg/install.bzl index 97320f2e..c0881058 100644 --- a/pkg/install.bzl +++ b/pkg/install.bzl @@ -205,6 +205,7 @@ def pkg_install(name, srcs, destdir = None, destdir_flag = None, **kwargs): 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 diff --git a/pkg/private/deb/BUILD b/pkg/private/deb/BUILD index cdb5c4d9..0ea90f66 100644 --- a/pkg/private/deb/BUILD +++ b/pkg/private/deb/BUILD @@ -52,6 +52,7 @@ py_binary( "make_deb.py", ], imports = ["../../.."], + legacy_create_init = 0, python_version = "PY3", visibility = ["//visibility:public"], deps = [ diff --git a/pkg/private/tar/BUILD b/pkg/private/tar/BUILD index d5c51c4b..0f702498 100644 --- a/pkg/private/tar/BUILD +++ b/pkg/private/tar/BUILD @@ -51,6 +51,7 @@ py_binary( "build_tar.py", ], imports = ["../../.."], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", visibility = ["//visibility:public"], diff --git a/pkg/private/zip/BUILD b/pkg/private/zip/BUILD index 562a6aa6..efd99b2e 100644 --- a/pkg/private/zip/BUILD +++ b/pkg/private/zip/BUILD @@ -52,6 +52,7 @@ py_binary( "build_zip.py", ], imports = ["../../.."], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", visibility = ["//visibility:public"], diff --git a/pkg/releasing/BUILD b/pkg/releasing/BUILD index 8092e5be..87cfd33b 100644 --- a/pkg/releasing/BUILD +++ b/pkg/releasing/BUILD @@ -45,6 +45,7 @@ py_binary( "print_rel_notes.py", ], imports = ["../.."], + legacy_create_init = 0, python_version = "PY3", deps = [ ":release_utils", @@ -54,6 +55,7 @@ py_binary( py_test( name = "release_tools_test", srcs = ["release_tools_test.py"], + legacy_create_init = 0, python_version = "PY3", deps = [ ":release_utils", @@ -67,6 +69,7 @@ py_binary( "__init__.py", "git_changelog_private.py", ], + legacy_create_init = 0, srcs_version = "PY3", # TODO(https://github.com/bazelbuild/bazel/issues/7377): Make this private. visibility = ["//visibility:public"], diff --git a/pkg/rpm/BUILD b/pkg/rpm/BUILD index 27f2a54c..cd0c79aa 100644 --- a/pkg/rpm/BUILD +++ b/pkg/rpm/BUILD @@ -42,5 +42,6 @@ py_binary( "__init__.py", "augment_rpm_files_install.py", ], + legacy_create_init = 0, visibility = ["//visibility:public"], ) diff --git a/tests/BUILD b/tests/BUILD index 93b4626c..e3c1f522 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -93,6 +93,7 @@ py_test( "//tests:testdata/empty.ar", ], imports = [".."], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", deps = [ @@ -105,6 +106,7 @@ py_test( name = "path_test", srcs = ["path_test.py"], data = ["//pkg:path.bzl"], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", ) @@ -135,6 +137,7 @@ py_test( name = "helpers_test", srcs = ["helpers_test.py"], imports = [".."], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", deps = [ @@ -214,6 +217,7 @@ py_test( "stamped_tar.tar", "stamped_zip.zip", ], + legacy_create_init = 0, python_version = "PY3", deps = [ "@rules_python//python/runfiles", diff --git a/tests/deb/BUILD b/tests/deb/BUILD index 2af1e41f..7ad6a914 100644 --- a/tests/deb/BUILD +++ b/tests/deb/BUILD @@ -124,6 +124,7 @@ py_test( ":test_deb_installed_size_file", ], imports = ["../.."], + legacy_create_init = 0, python_version = "PY3", deps = [ "//pkg/private:archive", @@ -144,6 +145,7 @@ py_test( "control_field_test.py", ], imports = ["../.."], + legacy_create_init = 0, python_version = "PY3", deps = [ "//pkg/private/deb:make_deb_lib", @@ -202,6 +204,7 @@ py_test( ":deb_with_package_variables", ], imports = ["../.."], + legacy_create_init = 0, python_version = "PY3", deps = [ "//pkg/private:archive", diff --git a/tests/install/BUILD b/tests/install/BUILD index 81019397..9c35444e 100644 --- a/tests/install/BUILD +++ b/tests/install/BUILD @@ -30,6 +30,7 @@ py_test( "@mappings_test_external_repo//pkg:install_cross_repo", ], imports = ["../.."], + legacy_create_init = 0, main = "test.py", tags = [ # TODO(nacl): investigate this. See also diff --git a/tests/mappings/filter_directory/BUILD b/tests/mappings/filter_directory/BUILD index a1ff831b..34baf18c 100644 --- a/tests/mappings/filter_directory/BUILD +++ b/tests/mappings/filter_directory/BUILD @@ -227,6 +227,7 @@ directory( py_test( name = "negative_tests", srcs = ["test_filter_directory.py"], + legacy_create_init = 0, main = "test_filter_directory.py", deps = [ "//pkg:filter_directory_lib", diff --git a/tests/rpm/BUILD b/tests/rpm/BUILD index 8a262978..7902f82d 100644 --- a/tests/rpm/BUILD +++ b/tests/rpm/BUILD @@ -660,6 +660,7 @@ py_library( py_test( name = "make_rpm_test", srcs = ["make_rpm_test.py"], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", deps = [ @@ -672,6 +673,7 @@ py_test( name = "pkg_rpm_basic_test", srcs = ["pkg_rpm_basic_test.py"], data = [":pkg_rpm_basic_test_data"], + legacy_create_init = 0, python_version = "PY3", tags = [ "no_windows", # Windows doesn't have rpm(8) or rpmbuild(8) diff --git a/tests/rpm/source_date_epoch/BUILD b/tests/rpm/source_date_epoch/BUILD index 59c944f5..95f5ea8d 100644 --- a/tests/rpm/source_date_epoch/BUILD +++ b/tests/rpm/source_date_epoch/BUILD @@ -30,6 +30,7 @@ py_test( srcs = ["rpm_contents_vs_manifest_test.py"], data = [":rpm_sde_insource_data"], env = {"TEST_RPM": "rpm_sde_insource-1.1.1-2222.noarch.rpm"}, + legacy_create_init = 0, main = "rpm_contents_vs_manifest_test.py", tags = [ "no_windows", # Windows doesn't have rpm(8) or rpmbuild(8) @@ -96,6 +97,7 @@ py_test( srcs = ["rpm_contents_vs_manifest_test.py"], data = [":rpm_sde_fromfile_data"], env = {"TEST_RPM": "rpm_sde_fromfile-1.1.1-2222.noarch.rpm"}, + legacy_create_init = 0, main = "rpm_contents_vs_manifest_test.py", tags = [ "no_windows", # Windows doesn't have rpm(8) or rpmbuild(8) diff --git a/tests/rpm/tree_artifacts/BUILD b/tests/rpm/tree_artifacts/BUILD index a1f13444..74b81529 100644 --- a/tests/rpm/tree_artifacts/BUILD +++ b/tests/rpm/tree_artifacts/BUILD @@ -46,6 +46,7 @@ py_test( srcs = ["rpm_contents_vs_manifest_test.py"], data = [":layer_with_files_test_data"], env = {"TEST_RPM": "test_dirs_rpm-1.1.1-2222.noarch.rpm"}, + legacy_create_init = 0, main = "rpm_contents_vs_manifest_test.py", tags = [ "no_windows", # Windows doesn't have rpm(8) or rpmbuild(8) @@ -155,6 +156,7 @@ py_test( srcs = ["rpm_contents_vs_manifest_test.py"], data = [":layer_with_files_reversed_test_data"], env = {"TEST_RPM": "test_dirs_rpm_reversed-1.1.1-2222.noarch.rpm"}, + legacy_create_init = 0, main = "rpm_contents_vs_manifest_test.py", tags = [ "no_windows", # Windows doesn't have rpm(8) or rpmbuild(8) @@ -207,6 +209,7 @@ py_test( srcs = ["rpm_treeartifact_ops_test.py"], data = [":treeartifact_ops_rpm_test_data"], env = {"TEST_RPM": "treeartifact_ops_rpm-1.1.1-2222.noarch.rpm"}, + legacy_create_init = 0, main = "rpm_treeartifact_ops_test.py", tags = [ "no_windows", # Windows doesn't have rpm(8) or rpmbuild(8) diff --git a/tests/tar/BUILD b/tests/tar/BUILD index ec020bbb..0c06f0de 100644 --- a/tests/tar/BUILD +++ b/tests/tar/BUILD @@ -49,6 +49,7 @@ py_test( "//tests:testdata/test_tar_package_dir_file.txt", ], imports = ["../.."], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", deps = [ @@ -82,6 +83,7 @@ directory( py_binary( name = "compressor", srcs = ["compressor.py"], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", ) @@ -524,6 +526,7 @@ py_test( for compression in SUPPORTED_TAR_COMPRESSIONS ], imports = ["../.."], + legacy_create_init = 0, python_version = "PY3", deps = [ "//pkg/private/tar:tar_writer", @@ -607,6 +610,7 @@ py_test( ":test-tar-compression-from-extension-targz", ":test-tar-compression-from-extension-tgz", ], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", deps = [ diff --git a/tests/util/BUILD b/tests/util/BUILD index 0be64823..36337ae6 100644 --- a/tests/util/BUILD +++ b/tests/util/BUILD @@ -23,6 +23,7 @@ exports_files(["defs.bzl"]) py_binary( name = "md5", srcs = ["md5.py"], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", visibility = ["//visibility:public"], @@ -31,6 +32,7 @@ py_binary( py_binary( name = "create_directory_with_contents", srcs = ["create_directory_with_contents.py"], + legacy_create_init = 0, python_version = "PY3", srcs_version = "PY3", visibility = ["//visibility:public"], diff --git a/tests/zip/BUILD b/tests/zip/BUILD index c2c42761..3d68fd18 100644 --- a/tests/zip/BUILD +++ b/tests/zip/BUILD @@ -307,6 +307,7 @@ py_test( ":test_zip_timestamp.zip", ":test_zip_tree.zip", ], + legacy_create_init = 0, python_version = "PY3", deps = [ ":zip_test_lib", @@ -321,6 +322,7 @@ py_test( data = [ ":test_zip_symlink", ], + legacy_create_init = 0, python_version = "PY3", tags = ["REQUIRES_BAZEL_8"], deps = [ @@ -345,6 +347,7 @@ py_test( ":test_zip_package_dir1.zip", ":test_zip_package_dir2.zip", ], + legacy_create_init = 0, python_version = "PY3", deps = [ ":zip_test_lib", @@ -364,6 +367,7 @@ py_test( data = [ ":unicode_names", ], + legacy_create_init = 0, python_version = "PY3", deps = [ ":zip_test_lib",