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.
diff --git a/distro/BUILD b/distro/BUILD
index aa0862f..95c8643 100644
--- a/distro/BUILD
+++ b/distro/BUILD
@@ -102,6 +102,7 @@
],
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 b144f5a..2f5c4f0 100644
--- a/doc_build/BUILD
+++ b/doc_build/BUILD
@@ -123,6 +123,7 @@
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 344465d..2e3540e 100644
--- a/pkg/BUILD
+++ b/pkg/BUILD
@@ -75,6 +75,7 @@
"make_rpm.py",
],
imports = [".."],
+ legacy_create_init = 0,
python_version = "PY3",
srcs_version = "PY3",
target_compatible_with = select({
@@ -110,6 +111,7 @@
"__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 97320f2..c088105 100644
--- a/pkg/install.bzl
+++ b/pkg/install.bzl
@@ -205,6 +205,7 @@
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 cdb5c4d..0ea90f6 100644
--- a/pkg/private/deb/BUILD
+++ b/pkg/private/deb/BUILD
@@ -52,6 +52,7 @@
"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 d5c51c4..0f70249 100644
--- a/pkg/private/tar/BUILD
+++ b/pkg/private/tar/BUILD
@@ -51,6 +51,7 @@
"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 562a6aa..efd99b2 100644
--- a/pkg/private/zip/BUILD
+++ b/pkg/private/zip/BUILD
@@ -52,6 +52,7 @@
"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 8092e5b..87cfd33 100644
--- a/pkg/releasing/BUILD
+++ b/pkg/releasing/BUILD
@@ -45,6 +45,7 @@
"print_rel_notes.py",
],
imports = ["../.."],
+ legacy_create_init = 0,
python_version = "PY3",
deps = [
":release_utils",
@@ -54,6 +55,7 @@
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 @@
"__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 27f2a54..cd0c79a 100644
--- a/pkg/rpm/BUILD
+++ b/pkg/rpm/BUILD
@@ -42,5 +42,6 @@
"__init__.py",
"augment_rpm_files_install.py",
],
+ legacy_create_init = 0,
visibility = ["//visibility:public"],
)
diff --git a/tests/BUILD b/tests/BUILD
index 93b4626..e3c1f52 100644
--- a/tests/BUILD
+++ b/tests/BUILD
@@ -93,6 +93,7 @@
"//tests:testdata/empty.ar",
],
imports = [".."],
+ legacy_create_init = 0,
python_version = "PY3",
srcs_version = "PY3",
deps = [
@@ -105,6 +106,7 @@
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 @@
name = "helpers_test",
srcs = ["helpers_test.py"],
imports = [".."],
+ legacy_create_init = 0,
python_version = "PY3",
srcs_version = "PY3",
deps = [
@@ -214,6 +217,7 @@
"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 2af1e41..7ad6a91 100644
--- a/tests/deb/BUILD
+++ b/tests/deb/BUILD
@@ -124,6 +124,7 @@
":test_deb_installed_size_file",
],
imports = ["../.."],
+ legacy_create_init = 0,
python_version = "PY3",
deps = [
"//pkg/private:archive",
@@ -144,6 +145,7 @@
"control_field_test.py",
],
imports = ["../.."],
+ legacy_create_init = 0,
python_version = "PY3",
deps = [
"//pkg/private/deb:make_deb_lib",
@@ -202,6 +204,7 @@
":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 8101939..9c35444 100644
--- a/tests/install/BUILD
+++ b/tests/install/BUILD
@@ -30,6 +30,7 @@
"@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 a1ff831..34baf18 100644
--- a/tests/mappings/filter_directory/BUILD
+++ b/tests/mappings/filter_directory/BUILD
@@ -227,6 +227,7 @@
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 6ca5449..b9422ab 100644
--- a/tests/rpm/BUILD
+++ b/tests/rpm/BUILD
@@ -704,6 +704,7 @@
py_test(
name = "make_rpm_test",
srcs = ["make_rpm_test.py"],
+ legacy_create_init = 0,
python_version = "PY3",
srcs_version = "PY3",
deps = [
@@ -716,6 +717,7 @@
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 59c944f..95f5ea8 100644
--- a/tests/rpm/source_date_epoch/BUILD
+++ b/tests/rpm/source_date_epoch/BUILD
@@ -30,6 +30,7 @@
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 @@
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 a1f1344..74b8152 100644
--- a/tests/rpm/tree_artifacts/BUILD
+++ b/tests/rpm/tree_artifacts/BUILD
@@ -46,6 +46,7 @@
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 @@
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 @@
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 ec020bb..0c06f0d 100644
--- a/tests/tar/BUILD
+++ b/tests/tar/BUILD
@@ -49,6 +49,7 @@
"//tests:testdata/test_tar_package_dir_file.txt",
],
imports = ["../.."],
+ legacy_create_init = 0,
python_version = "PY3",
srcs_version = "PY3",
deps = [
@@ -82,6 +83,7 @@
py_binary(
name = "compressor",
srcs = ["compressor.py"],
+ legacy_create_init = 0,
python_version = "PY3",
srcs_version = "PY3",
)
@@ -524,6 +526,7 @@
for compression in SUPPORTED_TAR_COMPRESSIONS
],
imports = ["../.."],
+ legacy_create_init = 0,
python_version = "PY3",
deps = [
"//pkg/private/tar:tar_writer",
@@ -607,6 +610,7 @@
":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 0be6482..36337ae 100644
--- a/tests/util/BUILD
+++ b/tests/util/BUILD
@@ -23,6 +23,7 @@
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(
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 c2c4276..3d68fd1 100644
--- a/tests/zip/BUILD
+++ b/tests/zip/BUILD
@@ -307,6 +307,7 @@
":test_zip_timestamp.zip",
":test_zip_tree.zip",
],
+ legacy_create_init = 0,
python_version = "PY3",
deps = [
":zip_test_lib",
@@ -321,6 +322,7 @@
data = [
":test_zip_symlink",
],
+ legacy_create_init = 0,
python_version = "PY3",
tags = ["REQUIRES_BAZEL_8"],
deps = [
@@ -345,6 +347,7 @@
":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 @@
data = [
":unicode_names",
],
+ legacy_create_init = 0,
python_version = "PY3",
deps = [
":zip_test_lib",