Skip to content

Commit 1e187c4

Browse files
committed
attempt to use whl_mod approach
1 parent 2de4153 commit 1e187c4

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

python/private/pypi/extension.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def _whl_mods_impl(whl_mods_dict):
4949
data = mods.data,
5050
data_exclude_glob = mods.data_exclude_glob,
5151
srcs_exclude_glob = mods.srcs_exclude_glob,
52+
enable_implicit_namespace_pkgs = mods.enable_implicit_namespace_pkgs,
5253
))
5354

5455
_whl_mods_repo(
@@ -178,6 +179,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
178179
data = whl_mod.data,
179180
data_exclude_glob = whl_mod.data_exclude_glob,
180181
srcs_exclude_glob = whl_mod.srcs_exclude_glob,
182+
enable_implicit_namespace_pkgs = whl_mod.enable_implicit_namespace_pkgs,
181183
)
182184

183185
config = build_config(module_ctx = module_ctx, enable_pipstar = enable_pipstar)
@@ -741,6 +743,12 @@ cannot have a child module that uses the same `hub_name`.
741743
doc = "The whl name that the modifications are used for.",
742744
mandatory = True,
743745
),
746+
"enable_implicit_namespace_pkgs": attr.bool(
747+
doc = """\
748+
(bool, optional): Override the global setting for generating __init__.py
749+
files for namespace packages. If None, uses the repository-level setting.
750+
""",
751+
),
744752
}
745753
return attrs
746754

tests/pypi/extension/extension_tests.bzl

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ simple==0.0.1 \
4949
],
5050
)
5151

52+
def _whl_mod(*, hub_name, whl_name, additive_build_content = None, additive_build_content_file = None, copy_executables = {}, copy_files = {}, data = [], data_exclude_glob = [], srcs_exclude_glob = [], enable_implicit_namespace_pkgs = None):
53+
return struct(
54+
hub_name = hub_name,
55+
whl_name = whl_name,
56+
additive_build_content = additive_build_content,
57+
additive_build_content_file = additive_build_content_file,
58+
copy_executables = copy_executables,
59+
copy_files = copy_files,
60+
data = data,
61+
data_exclude_glob = data_exclude_glob,
62+
srcs_exclude_glob = srcs_exclude_glob,
63+
enable_implicit_namespace_pkgs = enable_implicit_namespace_pkgs,
64+
)
65+
5266
def _mod(*, name, default = [], parse = [], override = [], whl_mods = [], is_root = True):
5367
return struct(
5468
name = name,
@@ -234,6 +248,69 @@ def _test_build_pipstar_platform(env):
234248

235249
_tests.append(_test_build_pipstar_platform)
236250

251+
def _test_whl_mods_with_namespace_pkgs(env):
252+
pypi = _parse_modules(
253+
env,
254+
module_ctx = _mock_mctx(
255+
_mod(
256+
name = "rules_python",
257+
parse = [
258+
_parse(
259+
hub_name = "pypi",
260+
python_version = "3.15",
261+
requirements_lock = "requirements.txt",
262+
),
263+
],
264+
whl_mods = [
265+
_whl_mod(
266+
hub_name = "pypi",
267+
whl_name = "simple",
268+
additive_build_content = "# Custom build content",
269+
enable_implicit_namespace_pkgs = True,
270+
),
271+
],
272+
),
273+
),
274+
available_interpreters = {
275+
"python_3_15_host": "unit_test_interpreter_target",
276+
},
277+
minor_mapping = {"3.15": "3.15.19"},
278+
)
279+
280+
pypi.exposed_packages().contains_exactly({"pypi": ["simple"]})
281+
pypi.hub_group_map().contains_exactly({"pypi": {}})
282+
pypi.hub_whl_map().contains_exactly({"pypi": {
283+
"simple": {
284+
"pypi_315_simple": [
285+
whl_config_setting(
286+
version = "3.15",
287+
),
288+
],
289+
},
290+
}})
291+
pypi.whl_libraries().contains_exactly({
292+
"pypi_315_simple": {
293+
"dep_template": "@pypi//{name}:{target}",
294+
"python_interpreter_target": "unit_test_interpreter_target",
295+
"requirement": "simple==0.0.1 --hash=sha256:deadbeef --hash=sha256:deadbaaf",
296+
},
297+
})
298+
pypi.whl_mods().contains_exactly({
299+
"pypi": {
300+
"simple": struct(
301+
build_content = "# Custom build content",
302+
copy_files = {},
303+
copy_executables = {},
304+
data = [],
305+
data_exclude_glob = [],
306+
srcs_exclude_glob = [],
307+
enable_implicit_namespace_pkgs = True,
308+
),
309+
},
310+
})
311+
312+
_tests.append(_test_whl_mods_with_namespace_pkgs)
313+
237314
def extension_test_suite(name):
238315
"""Create the test suite.
239316

0 commit comments

Comments
 (0)