Skip to content

Commit 74383f3

Browse files
committed
fix the tests
1 parent e2c07ae commit 74383f3

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

examples/bzlmod/MODULE.bazel.lock

Lines changed: 1 addition & 1 deletion
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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,24 @@ def _create_whl_repos(
327327
args["requirement"] = requirement.requirement_line
328328
if requirement.extra_pip_args:
329329
args["extra_pip_args"] = requirement.extra_pip_args
330+
330331
if pip_attr.download_only:
331332
args.setdefault("experimental_target_platforms", requirement.target_platforms)
332333

333-
repo_name = pypi_repo_name(pip_name, requirement.srcs.requirement, requirement.srcs.version)
334+
target_platforms = requirement.target_platforms if len(requirements) > 1 else []
335+
repo_name = pypi_repo_name(
336+
pip_name,
337+
requirement.srcs.requirement,
338+
requirement.srcs.version,
339+
# Strip the leading cp3x prefix
340+
"_".join([p.partition("_")[-1] for p in target_platforms]),
341+
)
334342
whl_libraries[repo_name] = args
335343
whl_map.setdefault(whl_name, []).append(
336344
whl_alias(
337345
repo = repo_name,
338346
version = major_minor,
339-
target_platforms = requirement.target_platforms if len(requirements) > 1 else None,
347+
target_platforms = target_platforms or None,
340348
),
341349
)
342350

python/private/pypi/whl_repo_name.bzl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ def whl_repo_name(prefix, filename, sha256):
5151

5252
return "_".join(parts)
5353

54-
def pypi_repo_name(prefix, requirement, version):
54+
def pypi_repo_name(prefix, requirement, version, platform_suffix = ""):
5555
"""Return a valid whl_library given a requirement line.
5656
5757
Args:
5858
prefix: {type}`str` the prefix of the whl_library.
5959
requirement: {type}`str` the requirement to extract the name.
6060
version: {type}`str` the requirement to extract the name.
61+
platform_suffix: {type}`str` the platform to use in the name.
6162
6263
Returns:
6364
{type}`str` that can be used in {obj}`whl_library`.
@@ -66,5 +67,12 @@ def pypi_repo_name(prefix, requirement, version):
6667
suffix, _, _ = suffix.partition("]")
6768
suffix = normalize_name(suffix.replace("[", "_").replace(",", "_"))
6869
version = version.replace("-", "_").replace("+", "_").replace(".", "_")
70+
parts = [
71+
prefix,
72+
normalize_name(suffix),
73+
"v" + version,
74+
]
75+
if platform_suffix:
76+
parts.append(platform_suffix)
6977

70-
return "{}_{}_v{}".format(prefix, normalize_name(suffix), version)
78+
return "_".join(parts)

tests/pypi/extension/extension_tests.bzl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ def _test_simple(env):
157157
struct(
158158
config_setting = "//_config:is_python_3.15",
159159
filename = None,
160-
repo = "pypi_315_simple",
160+
repo = "pypi_315_simple_v0_0_1",
161161
target_platforms = None,
162162
version = "3.15",
163163
),
164164
],
165165
}})
166166
pypi.whl_libraries().contains_exactly({
167-
"pypi_315_simple": {
167+
"pypi_315_simple_v0_0_1": {
168168
"dep_template": "@pypi//{name}:{target}",
169169
"python_interpreter_target": "unit_test_interpreter_target",
170170
"repo": "pypi_315",
@@ -208,7 +208,7 @@ def _test_simple_multiple_requirements(env):
208208
struct(
209209
config_setting = "//_config:is_python_3.15",
210210
filename = None,
211-
repo = "pypi_315_simple__windows_x86_64",
211+
repo = "pypi_315_simple_v0_0_1_windows_x86_64",
212212
target_platforms = [
213213
"cp315_windows_x86_64",
214214
],
@@ -217,7 +217,7 @@ def _test_simple_multiple_requirements(env):
217217
struct(
218218
config_setting = "//_config:is_python_3.15",
219219
filename = None,
220-
repo = "pypi_315_simple__osx_aarch64_osx_x86_64",
220+
repo = "pypi_315_simple_v0_0_2_osx_aarch64_osx_x86_64",
221221
target_platforms = [
222222
"cp315_osx_aarch64",
223223
"cp315_osx_x86_64",
@@ -227,17 +227,17 @@ def _test_simple_multiple_requirements(env):
227227
],
228228
}})
229229
pypi.whl_libraries().contains_exactly({
230-
"pypi_315_simple__osx_aarch64_osx_x86_64": {
230+
"pypi_315_simple_v0_0_1_windows_x86_64": {
231231
"dep_template": "@pypi//{name}:{target}",
232232
"python_interpreter_target": "unit_test_interpreter_target",
233233
"repo": "pypi_315",
234-
"requirement": "simple==0.0.2 --hash=sha256:deadb00f",
234+
"requirement": "simple==0.0.1 --hash=sha256:deadbeef",
235235
},
236-
"pypi_315_simple__windows_x86_64": {
236+
"pypi_315_simple_v0_0_2_osx_aarch64_osx_x86_64": {
237237
"dep_template": "@pypi//{name}:{target}",
238238
"python_interpreter_target": "unit_test_interpreter_target",
239239
"repo": "pypi_315",
240-
"requirement": "simple==0.0.1 --hash=sha256:deadbeef",
240+
"requirement": "simple==0.0.2 --hash=sha256:deadb00f",
241241
},
242242
})
243243
pypi.whl_mods().contains_exactly({})
@@ -295,7 +295,7 @@ simple==0.0.3 --hash=sha256:deadbaaf
295295
struct(
296296
config_setting = "//_config:is_python_3.15",
297297
filename = None,
298-
repo = "pypi_315_extra",
298+
repo = "pypi_315_extra_v0_0_1",
299299
target_platforms = None,
300300
version = "3.15",
301301
),
@@ -304,21 +304,21 @@ simple==0.0.3 --hash=sha256:deadbaaf
304304
struct(
305305
config_setting = "//_config:is_python_3.15",
306306
filename = None,
307-
repo = "pypi_315_simple__linux_x86_64",
307+
repo = "pypi_315_simple_v0_0_1_linux_x86_64",
308308
target_platforms = ["cp315_linux_x86_64"],
309309
version = "3.15",
310310
),
311311
struct(
312312
config_setting = "//_config:is_python_3.15",
313313
filename = None,
314-
repo = "pypi_315_simple__osx_aarch64",
314+
repo = "pypi_315_simple_v0_0_3_osx_aarch64",
315315
target_platforms = ["cp315_osx_aarch64"],
316316
version = "3.15",
317317
),
318318
],
319319
}})
320320
pypi.whl_libraries().contains_exactly({
321-
"pypi_315_extra": {
321+
"pypi_315_extra_v0_0_1": {
322322
"dep_template": "@pypi//{name}:{target}",
323323
"download_only": True,
324324
"experimental_target_platforms": ["cp315_linux_x86_64"],
@@ -327,7 +327,7 @@ simple==0.0.3 --hash=sha256:deadbaaf
327327
"repo": "pypi_315",
328328
"requirement": "extra==0.0.1 --hash=sha256:deadb00f",
329329
},
330-
"pypi_315_simple__linux_x86_64": {
330+
"pypi_315_simple_v0_0_1_linux_x86_64": {
331331
"dep_template": "@pypi//{name}:{target}",
332332
"download_only": True,
333333
"experimental_target_platforms": ["cp315_linux_x86_64"],
@@ -336,7 +336,7 @@ simple==0.0.3 --hash=sha256:deadbaaf
336336
"repo": "pypi_315",
337337
"requirement": "simple==0.0.1 --hash=sha256:deadbeef",
338338
},
339-
"pypi_315_simple__osx_aarch64": {
339+
"pypi_315_simple_v0_0_3_osx_aarch64": {
340340
"dep_template": "@pypi//{name}:{target}",
341341
"download_only": True,
342342
"experimental_target_platforms": ["cp315_osx_aarch64"],
@@ -429,7 +429,7 @@ some_pkg==0.0.1
429429
struct(
430430
config_setting = "//_config:is_python_3.15",
431431
filename = None,
432-
repo = "pypi_315_some_pkg",
432+
repo = "pypi_315_some_pkg_v0_0_1",
433433
target_platforms = None,
434434
version = "3.15",
435435
),
@@ -476,7 +476,7 @@ some_pkg==0.0.1
476476
"urls": ["example.org"],
477477
},
478478
# We are falling back to regular `pip`
479-
"pypi_315_some_pkg": {
479+
"pypi_315_some_pkg_v0_0_1": {
480480
"dep_template": "@pypi//{name}:{target}",
481481
"python_interpreter_target": "unit_test_interpreter_target",
482482
"repo": "pypi_315",

0 commit comments

Comments
 (0)