From aab37a53e64c01a610d0e77c1af4d7765d43d3db Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 20 Jun 2026 04:01:41 +0000 Subject: [PATCH 1/3] rules_python: Warn on implicit __init__.py creation. Warn users when targets rely on deprecated implicit __init__.py creation to encourage migration to explicit inits. We add a formatted multiline warning block inside the execution path of `_should_create_init_files(ctx)` in `py_executable.bzl`. The warning identifies the offending target by label and provides instructions on how to explicitly create inits or disable the warning. --- python/private/py_executable.bzl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/python/private/py_executable.bzl b/python/private/py_executable.bzl index 198ff9d548..13d2e0dad1 100644 --- a/python/private/py_executable.bzl +++ b/python/private/py_executable.bzl @@ -1485,6 +1485,25 @@ def _get_base_runfiles_for_binary( app_runfiles = app_runfiles.build(ctx) if _should_create_init_files(ctx): + # buildifier: disable=print + print( + """ +====================================================================== +WARNING: Target {} is using implicit __init__.py creation. + This diabolic behavior is deprecated and will be removed 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 by setting: + legacy_create_init = 0 + on the target, or globally by setting: + --incompatible_default_to_explicit_init_py +====================================================================== + """.rstrip().format(ctx.label), + ) app_runfiles = _py_builtins.merge_runfiles_with_generated_inits_empty_files_supplier( ctx = ctx, runfiles = app_runfiles, From d79065bdd43a5b721f5b8fa12d150debea455447 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 20 Jun 2026 04:03:39 +0000 Subject: [PATCH 2/3] docs: Add news entry for implicit init warning. Add a changelog news entry for the newly introduced deprecation warning on implicit __init__.py creation. --- news/2945.changed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/2945.changed.md diff --git a/news/2945.changed.md b/news/2945.changed.md new file mode 100644 index 0000000000..c0ff002661 --- /dev/null +++ b/news/2945.changed.md @@ -0,0 +1 @@ +(binaries/tests) Added a deprecation warning for targets relying on implicit `__init__.py` creation. From fa35966cb3c1bc94f47fe3edd0cd3249a2b1f7c5 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 20 Jun 2026 04:10:11 +0000 Subject: [PATCH 3/3] rules_python: Rephrase warning to 'disabled by default'. Clarify in the warning message that implicit __init__.py creation will be disabled by default (rather than completely removed) in a future release. --- python/private/py_executable.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/private/py_executable.bzl b/python/private/py_executable.bzl index 13d2e0dad1..04a43be917 100644 --- a/python/private/py_executable.bzl +++ b/python/private/py_executable.bzl @@ -1490,7 +1490,7 @@ def _get_base_runfiles_for_binary( """ ====================================================================== WARNING: Target {} is using implicit __init__.py creation. - This diabolic behavior is deprecated and will be removed in a + 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