Skip to content

Commit e27879a

Browse files
committed
Add _test_multiple_extras_multiple_requirements
Run with: ```console bazel test //tests/pypi/hub_builder:test_multiple_extras_multiple_requirements ```
1 parent cf594f7 commit e27879a

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

tests/pypi/hub_builder/hub_builder_tests.bzl

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,152 @@ optimum[onnxruntime-gpu]==1.17.1 ; sys_platform == 'linux'
10641064

10651065
_tests.append(_test_pipstar_platforms)
10661066

1067+
def _test_simple_multiple_extras_same_whl(env):
1068+
builder = hub_builder(env)
1069+
builder.pip_parse(
1070+
_mock_mctx(
1071+
read = lambda x: {
1072+
"darwin.txt": "simple==0.0.2 --hash=sha256:deadb00f",
1073+
"win.txt": "simple==0.0.1 --hash=sha256:deadbeef",
1074+
}[x],
1075+
),
1076+
_parse(
1077+
hub_name = "pypi",
1078+
python_version = "3.15",
1079+
requirements_darwin = "darwin.txt",
1080+
requirements_windows = "win.txt",
1081+
),
1082+
)
1083+
pypi = builder.build()
1084+
1085+
pypi.exposed_packages().contains_exactly(["simple"])
1086+
pypi.group_map().contains_exactly({})
1087+
pypi.whl_map().contains_exactly({
1088+
"simple": {
1089+
"pypi_315_simple_osx_aarch64": [
1090+
whl_config_setting(
1091+
target_platforms = [
1092+
"cp315_osx_aarch64",
1093+
],
1094+
version = "3.15",
1095+
),
1096+
],
1097+
"pypi_315_simple_windows_aarch64": [
1098+
whl_config_setting(
1099+
target_platforms = [
1100+
"cp315_windows_aarch64",
1101+
],
1102+
version = "3.15",
1103+
),
1104+
],
1105+
},
1106+
})
1107+
pypi.whl_libraries().contains_exactly({
1108+
"pypi_315_simple_osx_aarch64": {
1109+
"config_load": "@pypi//:config.bzl",
1110+
"dep_template": "@pypi//{name}:{target}",
1111+
"python_interpreter_target": "unit_test_interpreter_target",
1112+
"requirement": "simple==0.0.2 --hash=sha256:deadb00f",
1113+
},
1114+
"pypi_315_simple_windows_aarch64": {
1115+
"config_load": "@pypi//:config.bzl",
1116+
"dep_template": "@pypi//{name}:{target}",
1117+
"python_interpreter_target": "unit_test_interpreter_target",
1118+
"requirement": "simple==0.0.1 --hash=sha256:deadbeef",
1119+
},
1120+
})
1121+
pypi.extra_aliases().contains_exactly({})
1122+
1123+
_tests.append(_test_simple_multiple_extras_same_whl)
1124+
1125+
def _test_multiple_extras_multiple_requirements(env):
1126+
"""Test that reproduces an issue where multiple extras point to same whl.
1127+
1128+
Based on https://github.com/bazel-contrib/rules_python/issues/2797#issuecomment-3143914644.
1129+
"""
1130+
1131+
def mock_simpleapi_download(*_, **__):
1132+
return {
1133+
"package": parse_simpleapi_html(
1134+
url = "https://example.com/package",
1135+
content = '''
1136+
<a href="package-0.7.0.tar.gz#sha256=4dd8924f171ed73a4f1a6191e2f800ae1745069989b69fabc45593d6b6504003">package-0.7.0.tar.gz</a>
1137+
<a href="package-0.7.0-py3-none-any.whl#sha256=62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76">package-0.7.0-py3-none-any.whl</a>
1138+
''',
1139+
),
1140+
}
1141+
1142+
builder = hub_builder(
1143+
env,
1144+
available_interpreters = {
1145+
"python_3_12_host": "unit_test_interpreter_target",
1146+
},
1147+
minor_mapping = {"3.12": "3.12.11"},
1148+
simpleapi_download_fn = mock_simpleapi_download,
1149+
)
1150+
builder.pip_parse(
1151+
_mock_mctx(
1152+
read = lambda x: {
1153+
"requirements.linux_arm64.txt": '''\
1154+
package==0.7.0 \
1155+
--hash=sha256:4dd8924f171ed73a4f1a6191e2f800ae1745069989b69fabc45593d6b6504003 \
1156+
--hash=sha256:62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76
1157+
''',
1158+
"requirements.linux_x86_64.txt": '''\
1159+
package[extra]==0.7.0 \
1160+
--hash=sha256:62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76
1161+
''',
1162+
}[x],
1163+
),
1164+
_parse(
1165+
hub_name = "pypi",
1166+
python_version = "3.12",
1167+
download_only = True,
1168+
requirements_by_platform = {
1169+
"requirements.linux_arm64.txt": "linux_aarch64",
1170+
"requirements.linux_x86_64.txt": "linux_x86_64",
1171+
},
1172+
experimental_index_url = "pypi.org",
1173+
),
1174+
)
1175+
pypi = builder.build()
1176+
1177+
pypi.exposed_packages().contains_exactly(["package"])
1178+
pypi.group_map().contains_exactly({})
1179+
1180+
# TODO(hartikainen): Check these expectations.
1181+
pypi.whl_map().contains_exactly({
1182+
"package": {
1183+
"pypi_312_package_py3_none_any_62833036": [
1184+
whl_config_setting(
1185+
# TODO(hartikainen): The two platforms both use the same `.whl` and
1186+
# are thus included in the same `target_platforms` here.
1187+
target_platforms = ["cp312_linux_aarch64", "cp312_linux_x86_64"],
1188+
version = "3.12",
1189+
),
1190+
],
1191+
},
1192+
})
1193+
pypi.whl_libraries().contains_exactly({
1194+
# NOTE(hartikainen): The error stems here. We have two different platforms
1195+
# pointing to the same universal wheel, both just with different extras. The key
1196+
# clashes and probably needs the extras to be included in it.
1197+
"pypi_312_package_py3_none_any_62833036": {
1198+
"config_load": "@pypi//:config.bzl",
1199+
"dep_template": "@pypi//{name}:{target}",
1200+
"filename": "package-0.7.0-py3-none-any.whl",
1201+
"python_interpreter_target": "unit_test_interpreter_target",
1202+
# NOTE(hartikainen): This should say `package[extra]==0.7.0` for
1203+
# `linux_x86_64` platform and `package==0.7.0` for `linux_aarch64`
1204+
"requirement": "package[extra]==0.7.0",
1205+
"sha256": "62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76",
1206+
"urls": ["https://example.com/package/package-0.7.0-py3-none-any.whl"],
1207+
},
1208+
})
1209+
pypi.extra_aliases().contains_exactly({})
1210+
1211+
_tests.append(_test_multiple_extras_multiple_requirements)
1212+
10671213
def hub_builder_test_suite(name):
10681214
"""Create the test suite.
10691215

0 commit comments

Comments
 (0)