Skip to content

Commit c1e9e0c

Browse files
committed
feat(pypi): allow scoping pip.override to single hubs
If you use multiple pip.parse hubs for different platforms, it's possible you want to override wheels for a single platform, where previously pip.override would apply to all hubs. This is useful for GPU vs CPU dependencies on the same OS / arch combinations, where the wheel name isn't enough to differentiate.
1 parent e32b08f commit c1e9e0c

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

python/private/pypi/extension.bzl

+17-6
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ def _create_whl_repos(
193193
python_interpreter_target = python_interpreter_target,
194194
whl_patches = {
195195
p: json.encode(args)
196-
for p, args in whl_overrides.get(whl_name, {}).items()
196+
for p, args in (
197+
whl_overrides.get(hub_name, {}).get(whl_name, {}).items() +
198+
whl_overrides.get("", {}).get(whl_name, {}).items() # Overrides without a hub name apply to all hubs
199+
)
197200
},
198201
)
199202
whl_library_args.update({k: v for k, v in maybe_args.items() if v})
@@ -384,16 +387,18 @@ You cannot use both the additive_build_content and additive_build_content_file a
384387
_overriden_whl_set[attr.file] = None
385388

386389
for patch in attr.patches:
387-
if whl_name not in whl_overrides:
388-
whl_overrides[whl_name] = {}
390+
if attr.hub_name not in whl_overrides:
391+
whl_overrides[attr.hub_name] = {}
392+
if whl_name not in whl_overrides[attr.hub_name]:
393+
whl_overrides[attr.hub_name][whl_name] = {}
389394

390-
if patch not in whl_overrides[whl_name]:
391-
whl_overrides[whl_name][patch] = struct(
395+
if patch not in whl_overrides[attr.hub_name][whl_name]:
396+
whl_overrides[attr.hub_name][whl_name][patch] = struct(
392397
patch_strip = attr.patch_strip,
393398
whls = [],
394399
)
395400

396-
whl_overrides[whl_name][patch].whls.append(attr.file)
401+
whl_overrides[attr.hub_name][whl_name][patch].whls.append(attr.file)
397402

398403
# Used to track all the different pip hubs and the spoke pip Python
399404
# versions.
@@ -857,6 +862,12 @@ A list of patches to apply to the repository *after* 'whl_library' is extracted
857862
and BUILD.bazel file is generated.""",
858863
mandatory = True,
859864
),
865+
"hub_name": attr.string(
866+
doc = """
867+
The name of the pip repo to override the wheel in. If this is not provided the
868+
wheel is overridden in all pip hubs.
869+
""",
870+
),
860871
},
861872
doc = """\
862873
Apply any overrides (e.g. patches) to a given Python distribution defined by

0 commit comments

Comments
 (0)