Skip to content

Commit ab105fd

Browse files
committed
fix: Resolve incorrect platform specific dependency
1 parent da0e52f commit ab105fd

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

python/private/pypi/parse_requirements.bzl

+15-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ def _extract_version(entry):
4646
return version
4747
return None
4848

49+
def _extract_marker_string(entry):
50+
"""Extract the marker string from the requirement string.
51+
52+
Args:
53+
entry: {type}`str` The requirement string.
54+
"""
55+
marker_start = entry.find(";")
56+
if marker_start != -1:
57+
# Extract everything after ';' until --hashes if it exists or end of the string
58+
marker, _, _ = entry[marker_start + 1:].partition(" --hashes")
59+
return marker.strip()
60+
return ""
61+
4962
def parse_requirements(
5063
ctx,
5164
*,
@@ -111,8 +124,9 @@ def parse_requirements(
111124
# The requirement lines might have duplicate names because lines for extras
112125
# are returned as just the base package name. e.g., `foo[bar]` results
113126
# in an entry like `("foo", "foo[bar] == 1.0 ...")`.
127+
# Lines with different markers are not condidered duplicates.
114128
requirements_dict = {
115-
(normalize_name(entry[0]), _extract_version(entry[1])): entry
129+
(normalize_name(entry[0]), _extract_version(entry[1]), _extract_marker_string(entry[1])): entry
116130
for entry in sorted(
117131
parse_result.requirements,
118132
# Get the longest match and fallback to original WORKSPACE sorting,

python/private/pypi/pep508_env.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ _platform_system_values = {
3030
"windows": "Windows",
3131
}
3232
_sys_platform_values = {
33-
"linux": "posix",
33+
"linux": "linux",
3434
"osx": "darwin",
3535
"windows": "win32",
3636
}

tests/pypi/extension/extension_tests.bzl

+78
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,84 @@ git_dep @ git+https://git.server/repo/project@deadbeefdeadbeef
856856

857857
_tests.append(_test_simple_get_index)
858858

859+
def _test_optimum_sys_platform_extra(env):
860+
pypi = _parse_modules(
861+
env,
862+
module_ctx = _mock_mctx(
863+
_mod(
864+
name = "rules_python",
865+
parse = [
866+
_parse(
867+
hub_name = "pypi",
868+
python_version = "3.15",
869+
requirements_lock = "universal.txt",
870+
),
871+
],
872+
),
873+
read = lambda x: {
874+
"universal.txt": """\
875+
optimum[onnxruntime]==1.17.1 ; sys_platform == 'darwin'
876+
optimum[onnxruntime-gpu]==1.17.1 ; sys_platform == 'linux'
877+
""",
878+
}[x],
879+
),
880+
available_interpreters = {
881+
"python_3_15_host": "unit_test_interpreter_target",
882+
},
883+
)
884+
885+
pypi.exposed_packages().contains_exactly({"pypi": []})
886+
pypi.hub_group_map().contains_exactly({"pypi": {}})
887+
pypi.hub_whl_map().contains_exactly({
888+
"pypi": {
889+
"optimum": {
890+
"pypi_315_optimum_linux_aarch64_linux_arm_linux_ppc_linux_s390x_linux_x86_64": [
891+
whl_config_setting(
892+
version = "3.15",
893+
target_platforms = [
894+
"cp315_linux_aarch64",
895+
"cp315_linux_arm",
896+
"cp315_linux_ppc",
897+
"cp315_linux_s390x",
898+
"cp315_linux_x86_64",
899+
],
900+
config_setting = None,
901+
filename = None,
902+
),
903+
],
904+
"pypi_315_optimum_osx_aarch64_osx_x86_64": [
905+
whl_config_setting(
906+
version = "3.15",
907+
target_platforms = [
908+
"cp315_osx_aarch64",
909+
"cp315_osx_x86_64",
910+
],
911+
config_setting = None,
912+
filename = None,
913+
),
914+
],
915+
},
916+
},
917+
})
918+
919+
pypi.whl_libraries().contains_exactly({
920+
"pypi_315_optimum_linux_aarch64_linux_arm_linux_ppc_linux_s390x_linux_x86_64": {
921+
"dep_template": "@pypi//{name}:{target}",
922+
"python_interpreter_target": "unit_test_interpreter_target",
923+
"repo": "pypi_315",
924+
"requirement": "optimum[onnxruntime-gpu]==1.17.1",
925+
},
926+
"pypi_315_optimum_osx_aarch64_osx_x86_64": {
927+
"dep_template": "@pypi//{name}:{target}",
928+
"python_interpreter_target": "unit_test_interpreter_target",
929+
"repo": "pypi_315",
930+
"requirement": "optimum[onnxruntime]==1.17.1",
931+
},
932+
})
933+
pypi.whl_mods().contains_exactly({})
934+
935+
_tests.append(_test_optimum_sys_platform_extra)
936+
859937
def extension_test_suite(name):
860938
"""Create the test suite.
861939

0 commit comments

Comments
 (0)