Skip to content

Commit 3e543b2

Browse files
committed
Add _test_simple_multiple_platforms_with_extras
Run with: ```console bazel test //tests/pypi/extension:test_simple_multiple_platforms_with_extras ```
1 parent fe45faa commit 3e543b2

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

tests/pypi/extension/extension_tests.bzl

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,91 @@ new-package==0.0.1 --hash=sha256:deadb00f2
407407

408408
_tests.append(_test_simple_multiple_python_versions)
409409

410+
def _test_simple_multiple_extras_same_whl(env):
411+
"""Test that reproduces an issue where multiple extras point to same whl.
412+
413+
Based on https://github.com/bazel-contrib/rules_python/issues/2797#issuecomment-3143914644.
414+
"""
415+
pypi = _parse_modules(
416+
env,
417+
module_ctx = _mock_mctx(
418+
_mod(
419+
name = "rules_python",
420+
parse = [
421+
_parse(
422+
hub_name = "pypi",
423+
python_version = "3.12",
424+
download_only = True,
425+
requirements_by_platform = {
426+
"requirements.linux_arm64.txt": "linux_aarch64",
427+
"requirements.linux_x86_64.txt": "linux_x86_64",
428+
},
429+
experimental_index_url = "pypi.org",
430+
),
431+
],
432+
),
433+
read = lambda x: {
434+
"requirements.linux_arm64.txt": """\
435+
package==0.7.0 \
436+
--hash=sha256:4dd8924f171ed73a4f1a6191e2f800ae1745069989b69fabc45593d6b6504003 \
437+
--hash=sha256:62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76
438+
""",
439+
"requirements.linux_x86_64.txt": """\
440+
package[extra]==0.7.0 \
441+
--hash=sha256:62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76
442+
""",
443+
}[x],
444+
),
445+
available_interpreters = {
446+
"python_3_12_host": "unit_test_interpreter_target",
447+
},
448+
minor_mapping = {"3.12": "3.12.11"},
449+
simpleapi_download = lambda *_, **__: {
450+
"package": parse_simpleapi_html(
451+
url = "https://example.com/package",
452+
content = """
453+
<a href="package-0.7.0.tar.gz#sha256=4dd8924f171ed73a4f1a6191e2f800ae1745069989b69fabc45593d6b6504003">package-0.7.0.tar.gz</a>
454+
<a href="package-0.7.0-py3-none-any.whl#sha256=62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76">package-0.7.0-py3-none-any.whl</a>
455+
""",
456+
),
457+
},
458+
)
459+
460+
pypi.exposed_packages().contains_exactly({"pypi": ["package"]})
461+
# TODO(hartikainen): Check these expectations.
462+
pypi.hub_whl_map().contains_exactly({"pypi": {
463+
"package": {
464+
"pypi_312_package_py3_none_any_62833036": [
465+
whl_config_setting(
466+
# TODO(hartikainen): The two platforms both use the same `.whl` and
467+
# are thus included in the same `target_platforms` here.
468+
target_platforms = ["cp312_linux_aarch64", "cp312_linux_x86_64"],
469+
version = "3.12",
470+
),
471+
],
472+
},
473+
}})
474+
pypi.whl_libraries().contains_exactly({
475+
# NOTE(hartikainen): The error stems here. We have two different platforms
476+
# pointing to the same universal wheel, both just with different extras. The key
477+
# clashes and probably needs the extras to be included in it.
478+
"pypi_312_package_py3_none_any_62833036": {
479+
"dep_template": "@pypi//{name}:{target}",
480+
"download_only": True,
481+
"experimental_target_platforms": ["linux_aarch64", "linux_x86_64"],
482+
"filename": "package-0.7.0-py3-none-any.whl",
483+
"python_interpreter_target": "unit_test_interpreter_target",
484+
# NOTE(hartikainen): This should say `package[extra]==0.7.0` for
485+
# `linux_x86_64` platform and `package==0.7.0` for `linux_aarch64`
486+
"requirement": "package[extra]==0.7.0",
487+
"sha256": "62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76",
488+
"urls": ["https://example.com/package-0.7.0-py3-none-any.whl"],
489+
},
490+
})
491+
pypi.whl_mods().contains_exactly({})
492+
493+
_tests.append(_test_simple_multiple_extras_same_whl)
494+
410495
def _test_simple_with_markers(env):
411496
pypi = _parse_modules(
412497
env,

0 commit comments

Comments
 (0)