Skip to content

Commit c1aafac

Browse files
committed
Fix for clashing pypi extras
These changes make `test_simple_multiple_platforms_with_extras` pass but I don't have enough understanding of the interdependencies here to say if this is the right solution.
1 parent 392fece commit c1aafac

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

python/private/pypi/extension.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,14 @@ def _whl_repo(
428428
]
429429

430430
return struct(
431-
repo_name = whl_repo_name(src.filename, src.sha256),
431+
# TODO(hartikainen): I have no idea if this is correct. Should the repository
432+
# name be based on the requirement (distribution + target platforms) rather than
433+
# the specific wheel filename? Different requirements (e.g., with different
434+
# extras as in my test case) can resolve to the same wheel file, but they
435+
# probably need to be distinct repositories to handle their transitive
436+
# dependencies correctly.
437+
repo_name = pypi_repo_name(normalize_name(src.distribution), *src.target_platforms),
438+
# repo_name = whl_repo_name(src.filename, src.sha256),
432439
args = args,
433440
config_setting = whl_config_setting(
434441
version = python_version,

tests/pypi/extension/extension_tests.bzl

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ _tests.append(_test_simple_multiple_python_versions)
405405

406406
def _test_simple_multiple_platforms_with_extras(env):
407407
"""TODO(hartikainen): Test that reproduces a multi-platform-with-extras issue."""
408+
408409
# This test case is based on my issue where different requirement strings for the same package
409410
# (`jax` vs `jax[cuda12]`) for multiple platforms caused a "duplicate library" error (for details,
410411
# see https://github.com/bazel-contrib/rules_python/issues/2797#issuecomment-3143914644).
@@ -454,33 +455,42 @@ package[extra]==0.7.0 \
454455
)
455456

456457
pypi.exposed_packages().contains_exactly({"pypi": ["package"]})
458+
457459
# TODO(hartikainen): Check these expectations.
458460
pypi.hub_whl_map().contains_exactly({"pypi": {
459461
"package": {
460-
"pypi_312_package_py3_none_any_62833036": [
462+
"pypi_312_package_linux_aarch64": [
461463
whl_config_setting(
462-
# TODO(hartikainen): I think all these platforms use the same `.whl`
463-
# and thus all three platforms should be included in the same
464-
# `target_platforms` here?
465-
target_platforms = ["cp312_linux_arm64", "cp312_linux_x86_64"],
464+
target_platforms = ["cp312_linux_aarch64"],
465+
version = "3.12",
466+
),
467+
],
468+
"pypi_312_package_linux_x86_64": [
469+
whl_config_setting(
470+
target_platforms = ["cp312_linux_x86_64"],
466471
version = "3.12",
467472
),
468473
],
469474
},
470475
}})
471476
pypi.whl_libraries().contains_exactly({
472-
"pypi_312_package_py3_none_any_62833036": {
477+
"pypi_312_package_linux_aarch64": {
473478
"dep_template": "@pypi//{name}:{target}",
474-
"download_only": True,
475-
"experimental_target_platforms": ["linux_arm64", "linux_x86_64"],
479+
"experimental_target_platforms": ["linux_aarch64"],
480+
"filename": "package-0.7.0-py3-none-any.whl",
481+
"python_interpreter_target": "unit_test_interpreter_target",
482+
"requirement": "package==0.7.0",
483+
"sha256": "62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76",
484+
"urls": ["https://example.com/package/package-0.7.0-py3-none-any.whl"],
485+
},
486+
"pypi_312_package_linux_x86_64": {
487+
"dep_template": "@pypi//{name}:{target}",
488+
"experimental_target_platforms": ["linux_x86_64"],
476489
"filename": "package-0.7.0-py3-none-any.whl",
477490
"python_interpreter_target": "unit_test_interpreter_target",
478-
# NOTE(hartikainen): Perhaps this is part of the problem?
479-
# This should say `package[extra]==0.7.0` for `linux_x86_64` platform and
480-
# `package==0.7.0` for `linux_arm64`
481491
"requirement": "package[extra]==0.7.0",
482492
"sha256": "62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76",
483-
"urls": ["https://example.com/package-0.7.0-py3-none-any.whl"],
493+
"urls": ["https://example.com/package/package-0.7.0-py3-none-any.whl"],
484494
},
485495
})
486496
pypi.whl_mods().contains_exactly({})

0 commit comments

Comments
 (0)