Skip to content

Commit a2b8b52

Browse files
committed
wip
1 parent b7577ff commit a2b8b52

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

examples/bzlmod/MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/private/pypi/extension.bzl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,9 @@ def _create_whl_repos(
368368
target_platforms = requirement.target_platforms if len(requirements) > 1 else []
369369
repo_name = pypi_repo_name(
370370
pip_name,
371-
requirement.srcs.requirement,
372-
requirement.srcs.version,
373-
# Strip the leading cp3x prefix
374-
"_".join([p.partition("_")[-1] for p in target_platforms]),
375-
) if target_platforms else "{}_{}".format(pip_name, whl_name)
371+
whl_name,
372+
*target_platforms
373+
)
376374
whl_libraries[repo_name] = args
377375
whl_map.setdefault(whl_name, []).append(
378376
whl_alias(

python/private/pypi/whl_repo_name.bzl

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,21 @@ def whl_repo_name(prefix, filename, sha256):
5151

5252
return "_".join(parts)
5353

54-
def pypi_repo_name(prefix, requirement, version, platform_suffix = ""):
54+
def pypi_repo_name(prefix, whl_name, *target_platforms):
5555
"""Return a valid whl_library given a requirement line.
5656
5757
Args:
5858
prefix: {type}`str` the prefix of the whl_library.
59-
requirement: {type}`str` the requirement to extract the name.
60-
version: {type}`str` the requirement to extract the name.
61-
platform_suffix: {type}`str` the platform to use in the name.
59+
whl_name: {type}`str` the whl_name to use.
60+
*target_platforms: {type}`list[str]` the target platforms to use in the name.
6261
6362
Returns:
6463
{type}`str` that can be used in {obj}`whl_library`.
6564
"""
66-
suffix, _, _ = requirement.partition("=")
67-
suffix, _, _ = suffix.partition("]")
68-
suffix = normalize_name(suffix.replace("[", "_").replace(",", "_"))
69-
version = version.replace("-", "_").replace("+", "_").replace(".", "_")
7065
parts = [
7166
prefix,
72-
normalize_name(suffix),
73-
"v" + version,
67+
normalize_name(whl_name),
7468
]
75-
if platform_suffix:
76-
parts.append(platform_suffix)
69+
parts.extend([p.partition("_")[-1] for p in target_platforms])
7770

7871
return "_".join(parts)

tests/pypi/extension/extension_tests.bzl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def _parse(
8181
experimental_index_url = "",
8282
experimental_requirement_cycles = {},
8383
experimental_target_platforms = [],
84+
extra_hub_aliases = {},
8485
extra_pip_args = [],
8586
isolated = True,
8687
netrc = None,
@@ -107,6 +108,7 @@ def _parse(
107108
experimental_index_url = experimental_index_url,
108109
experimental_requirement_cycles = experimental_requirement_cycles,
109110
experimental_target_platforms = experimental_target_platforms,
111+
extra_hub_aliases = extra_hub_aliases,
110112
extra_pip_args = extra_pip_args,
111113
hub_name = hub_name,
112114
isolated = isolated,
@@ -210,7 +212,7 @@ def _test_simple_multiple_requirements(env):
210212
struct(
211213
config_setting = "//_config:is_python_3.15",
212214
filename = None,
213-
repo = "pypi_315_simple_v0_0_1_windows_x86_64",
215+
repo = "pypi_315_simple_windows_x86_64",
214216
target_platforms = [
215217
"cp315_windows_x86_64",
216218
],
@@ -219,7 +221,7 @@ def _test_simple_multiple_requirements(env):
219221
struct(
220222
config_setting = "//_config:is_python_3.15",
221223
filename = None,
222-
repo = "pypi_315_simple_v0_0_2_osx_aarch64_osx_x86_64",
224+
repo = "pypi_315_simple_osx_aarch64_osx_x86_64",
223225
target_platforms = [
224226
"cp315_osx_aarch64",
225227
"cp315_osx_x86_64",
@@ -229,17 +231,17 @@ def _test_simple_multiple_requirements(env):
229231
],
230232
}})
231233
pypi.whl_libraries().contains_exactly({
232-
"pypi_315_simple_v0_0_1_windows_x86_64": {
234+
"pypi_315_simple_osx_aarch64_osx_x86_64": {
233235
"dep_template": "@pypi//{name}:{target}",
234236
"python_interpreter_target": "unit_test_interpreter_target",
235237
"repo": "pypi_315",
236-
"requirement": "simple==0.0.1 --hash=sha256:deadbeef",
238+
"requirement": "simple==0.0.2 --hash=sha256:deadb00f",
237239
},
238-
"pypi_315_simple_v0_0_2_osx_aarch64_osx_x86_64": {
240+
"pypi_315_simple_windows_x86_64": {
239241
"dep_template": "@pypi//{name}:{target}",
240242
"python_interpreter_target": "unit_test_interpreter_target",
241243
"repo": "pypi_315",
242-
"requirement": "simple==0.0.2 --hash=sha256:deadb00f",
244+
"requirement": "simple==0.0.1 --hash=sha256:deadbeef",
243245
},
244246
})
245247
pypi.whl_mods().contains_exactly({})
@@ -306,14 +308,14 @@ simple==0.0.3 --hash=sha256:deadbaaf
306308
struct(
307309
config_setting = "//_config:is_python_3.15",
308310
filename = None,
309-
repo = "pypi_315_simple_v0_0_1_linux_x86_64",
311+
repo = "pypi_315_simple_linux_x86_64",
310312
target_platforms = ["cp315_linux_x86_64"],
311313
version = "3.15",
312314
),
313315
struct(
314316
config_setting = "//_config:is_python_3.15",
315317
filename = None,
316-
repo = "pypi_315_simple_v0_0_3_osx_aarch64",
318+
repo = "pypi_315_simple_osx_aarch64",
317319
target_platforms = ["cp315_osx_aarch64"],
318320
version = "3.15",
319321
),
@@ -329,7 +331,7 @@ simple==0.0.3 --hash=sha256:deadbaaf
329331
"repo": "pypi_315",
330332
"requirement": "extra==0.0.1 --hash=sha256:deadb00f",
331333
},
332-
"pypi_315_simple_v0_0_1_linux_x86_64": {
334+
"pypi_315_simple_linux_x86_64": {
333335
"dep_template": "@pypi//{name}:{target}",
334336
"download_only": True,
335337
"experimental_target_platforms": ["cp315_linux_x86_64"],
@@ -338,7 +340,7 @@ simple==0.0.3 --hash=sha256:deadbaaf
338340
"repo": "pypi_315",
339341
"requirement": "simple==0.0.1 --hash=sha256:deadbeef",
340342
},
341-
"pypi_315_simple_v0_0_3_osx_aarch64": {
343+
"pypi_315_simple_osx_aarch64": {
342344
"dep_template": "@pypi//{name}:{target}",
343345
"download_only": True,
344346
"experimental_target_platforms": ["cp315_osx_aarch64"],

0 commit comments

Comments
 (0)