Skip to content

Commit b3bb708

Browse files
author
Finn Ball
committed
feat: add ability to override hub name
1 parent 24a910d commit b3bb708

File tree

1 file changed

+41
-29
lines changed

1 file changed

+41
-29
lines changed

python/private/bzlmod/pip.bzl

+41-29
Original file line numberDiff line numberDiff line change
@@ -427,39 +427,45 @@ def _pip_impl(module_ctx):
427427
for mod in module_ctx.modules:
428428
for pip_attr in mod.tags.parse:
429429
hub_name = pip_attr.hub_name
430-
if hub_name not in pip_hub_map:
430+
# only override if the module is root.
431+
override = mod.is_root and pip_attr.override
432+
if hub_name not in pip_hub_map or override:
431433
pip_hub_map[pip_attr.hub_name] = struct(
432434
module_name = mod.name,
433435
python_versions = [pip_attr.python_version],
436+
pip_attr = pip_attr,
437+
override = override
434438
)
435-
elif pip_hub_map[hub_name].module_name != mod.name:
436-
# We cannot have two hubs with the same name in different
437-
# modules.
438-
fail((
439-
"Duplicate cross-module pip hub named '{hub}': pip hub " +
440-
"names must be unique across modules. First defined " +
441-
"by module '{first_module}', second attempted by " +
442-
"module '{second_module}'"
443-
).format(
444-
hub = hub_name,
445-
first_module = pip_hub_map[hub_name].module_name,
446-
second_module = mod.name,
447-
))
448-
449-
elif pip_attr.python_version in pip_hub_map[hub_name].python_versions:
450-
fail((
451-
"Duplicate pip python version '{version}' for hub " +
452-
"'{hub}' in module '{module}': the Python versions " +
453-
"used for a hub must be unique"
454-
).format(
455-
hub = hub_name,
456-
module = mod.name,
457-
version = pip_attr.python_version,
458-
))
459-
else:
460-
pip_hub_map[pip_attr.hub_name].python_versions.append(pip_attr.python_version)
461-
462-
_create_whl_repos(module_ctx, pip_attr, hub_whl_map, whl_overrides, simpleapi_cache)
439+
elif not pip_hub_map[hub_name].pip_attr.override:
440+
if pip_hub_map[hub_name].module_name != mod.name:
441+
# We cannot have two hubs with the same name in different
442+
# modules.
443+
fail((
444+
"Duplicate cross-module pip hub named '{hub}': pip hub " +
445+
"names must be unique across modules. First defined " +
446+
"by module '{first_module}', second attempted by " +
447+
"module '{second_module}'"
448+
).format(
449+
hub = hub_name,
450+
first_module = pip_hub_map[hub_name].module_name,
451+
second_module = mod.name,
452+
))
453+
454+
elif pip_attr.python_version in pip_hub_map[hub_name].python_versions:
455+
fail((
456+
"Duplicate pip python version '{version}' for hub " +
457+
"'{hub}' in module '{module}': the Python versions " +
458+
"used for a hub must be unique"
459+
).format(
460+
hub = hub_name,
461+
module = mod.name,
462+
version = pip_attr.python_version,
463+
))
464+
else:
465+
pip_hub_map[pip_attr.hub_name].python_versions.append(pip_attr.python_version)
466+
467+
for value in pip_hub_map.values():
468+
_create_whl_repos(module_ctx, value.pip_attr, hub_whl_map, whl_overrides, simpleapi_cache)
463469

464470
for hub_name, whl_map in hub_whl_map.items():
465471
pip_repository(
@@ -557,6 +563,12 @@ A dict of labels to wheel names that is typically generated by the whl_modificat
557563
The labels are JSON config files describing the modifications.
558564
""",
559565
),
566+
"override": attr.bool(
567+
default = False,
568+
doc = """
569+
If the module is root, this may override any hub_name's listed in the dependencies.
570+
"""
571+
),
560572
}, **pip_repository_attrs)
561573
attrs.update(AUTH_ATTRS)
562574

0 commit comments

Comments
 (0)