Skip to content

Commit 47c681b

Browse files
rickeylevaignas
andauthored
fix(pypi): only generate namespace package shims if implicit namespaces are disabled (#3059)
The refactoring to move the pkgutil shim generation to build phase inverted the logic for when it should be activated. When `enable_implicit_namespace_pkgs=True`, it means to not generate the pkgutil shims ("respect the Python definition of the namespace package"). To fix, just invert the logic that activates it. A test will be added in a subsequent PR because the necessary helper isn't in the 1.5 branch. Fixes #3038 --------- Co-authored-by: Ignas Anikevicius <[email protected]>
1 parent 2b5e6f5 commit 47c681b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ END_UNRELEASED_TEMPLATE
9696
### Removed
9797
* Nothing removed.
9898

99+
{#1-5-1}
100+
## [1.5.1] - 2025-07-06
101+
102+
[1.5.1]: https://github.com/bazel-contrib/rules_python/releases/tag/1.5.1
103+
104+
{#v1-5-1-fixed}
105+
### Fixed
106+
107+
* (pypi) Namespace packages work by default (pkgutil shims are generated
108+
by default again)
109+
([#3038](https://github.com/bazel-contrib/rules_python/issues/3038)).
110+
99111
{#1-5-0}
100112
## [1.5.0] - 2025-06-11
101113

python/private/pypi/whl_library_targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def whl_library_targets(
331331
allow_empty = True,
332332
)
333333

334-
if enable_implicit_namespace_pkgs:
334+
if not enable_implicit_namespace_pkgs:
335335
srcs = srcs + getattr(native, "select", select)({
336336
Label("//python/config_settings:is_venvs_site_packages"): [],
337337
"//conditions:default": create_inits(

tests/pypi/whl_library_targets/whl_library_targets_tests.bzl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@
1616

1717
load("@rules_testing//lib:test_suite.bzl", "test_suite")
1818
load("//python/private:glob_excludes.bzl", "glob_excludes") # buildifier: disable=bzl-visibility
19-
load("//python/private/pypi:whl_library_targets.bzl", "whl_library_targets", "whl_library_targets_from_requires") # buildifier: disable=bzl-visibility
19+
load("//python/private/pypi:whl_library_targets.bzl", _whl_library_targets = "whl_library_targets", _whl_library_targets_from_requires = "whl_library_targets_from_requires") # buildifier: disable=bzl-visibility
2020

2121
_tests = []
2222

23+
def whl_library_targets(**kwargs):
24+
# Let's skip testing this for now
25+
_whl_library_targets(enable_implicit_namespace_pkgs = True, **kwargs)
26+
27+
def whl_library_targets_from_requires(**kwargs):
28+
# Let's skip testing this for now
29+
_whl_library_targets_from_requires(enable_implicit_namespace_pkgs = True, **kwargs)
30+
2331
def _test_filegroups(env):
2432
calls = []
2533

0 commit comments

Comments
 (0)