Skip to content

Commit 01903fc

Browse files
authored
chore: warn on implicit __init__.py creation (#3841)
Implicit `__init__.py` creation is deprecated and will be disabled by default in a future release. We need to warn users when their targets rely on this behavior so they can transition to explicit `__init__.py` files before the default changes and their builds break. Work towards #2945
1 parent e9ecdba commit 01903fc

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

news/2945.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(binaries/tests) Added a deprecation warning for targets relying on implicit `__init__.py` creation.

python/private/py_executable.bzl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,25 @@ def _get_base_runfiles_for_binary(
14851485
app_runfiles = app_runfiles.build(ctx)
14861486

14871487
if _should_create_init_files(ctx):
1488+
# buildifier: disable=print
1489+
print(
1490+
"""
1491+
======================================================================
1492+
WARNING: Target {} is using implicit __init__.py creation.
1493+
This diabolic behavior is deprecated and will be disabled by default in a
1494+
future release.
1495+
See https://github.com/bazel-contrib/rules_python/issues/2945
1496+
1497+
Ensure all __init__.py files are explicitly created and
1498+
added to the srcs or deps of your targets.
1499+
1500+
Disable implicit creation by setting:
1501+
legacy_create_init = 0
1502+
on the target, or globally by setting:
1503+
--incompatible_default_to_explicit_init_py
1504+
======================================================================
1505+
""".rstrip().format(ctx.label),
1506+
)
14881507
app_runfiles = _py_builtins.merge_runfiles_with_generated_inits_empty_files_supplier(
14891508
ctx = ctx,
14901509
runfiles = app_runfiles,

0 commit comments

Comments
 (0)