@@ -407,6 +407,93 @@ new-package==0.0.1 --hash=sha256:deadb00f2
407407
408408_tests .append (_test_simple_multiple_python_versions )
409409
410+ def _test_simple_multiple_platforms_with_extras (env ):
411+ """TODO(hartikainen): Test that reproduces a multi-platform-with-extras issue."""
412+ # This test case is based on my issue where different requirement strings for the same package
413+ # (`jax` vs `jax[cuda12]`) for multiple platforms caused a "duplicate library" error (for details,
414+ # see https://github.com/bazel-contrib/rules_python/issues/2797#issuecomment-3143914644).
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): I think all these platforms use the same `.whl`
467+ # and thus all three platforms should be included in the same
468+ # `target_platforms` here?
469+ target_platforms = ["cp312_linux_aarch64" , "cp312_linux_x86_64" ],
470+ version = "3.12" ,
471+ ),
472+ ],
473+ },
474+ }})
475+ pypi .whl_libraries ().contains_exactly ({
476+ # The error stems here. We have two different platforms pointing to the same
477+ # universal wheel, both just with different extras. The key clashes and probably
478+ # needs the extras to be included in it.
479+ "pypi_312_package_py3_none_any_62833036" : {
480+ "dep_template" : "@pypi//{name}:{target}" ,
481+ "download_only" : True ,
482+ "experimental_target_platforms" : ["linux_aarch64" , "linux_x86_64" ],
483+ "filename" : "package-0.7.0-py3-none-any.whl" ,
484+ "python_interpreter_target" : "unit_test_interpreter_target" ,
485+ # NOTE(hartikainen): Perhaps this is part of the problem?
486+ # This should say `package[extra]==0.7.0` for `linux_x86_64` platform and
487+ # `package==0.7.0` for `linux_aarch64`
488+ "requirement" : "package[extra]==0.7.0" ,
489+ "sha256" : "62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76" ,
490+ "urls" : ["https://example.com/package-0.7.0-py3-none-any.whl" ],
491+ },
492+ })
493+ pypi .whl_mods ().contains_exactly ({})
494+
495+ _tests .append (_test_simple_multiple_platforms_with_extras )
496+
410497def _test_simple_with_markers (env ):
411498 pypi = _parse_modules (
412499 env ,
0 commit comments