Skip to content

Commit e827a01

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

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ Unreleased changes template.
8181

8282
{#v0-0-0-fixed}
8383
### Fixed
84+
* (pypi) Platform specific markers are now correctly handled when using `requirments_by_platform`
85+
in pip.parse.
8486
* (runfiles) ({obj}`--bootstrap_impl=script`) Follow symlinks when searching for runfiles.
8587
* (toolchains) Do not try to run `chmod` when downloading non-windows hermetic toolchain
8688
repositories on Windows. Fixes

python/private/pypi/parse_requirements.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ load("//python/private:normalize_name.bzl", "normalize_name")
3030
load("//python/private:repo_utils.bzl", "repo_utils")
3131
load(":index_sources.bzl", "index_sources")
3232
load(":parse_requirements_txt.bzl", "parse_requirements_txt")
33+
load(":pep508_req.bzl", "requirement")
3334
load(":whl_target_platforms.bzl", "select_whls")
3435

3536
def _extract_version(entry):
@@ -111,8 +112,9 @@ def parse_requirements(
111112
# The requirement lines might have duplicate names because lines for extras
112113
# are returned as just the base package name. e.g., `foo[bar]` results
113114
# in an entry like `("foo", "foo[bar] == 1.0 ...")`.
115+
# Lines with different markers are not condidered duplicates.
114116
requirements_dict = {
115-
(normalize_name(entry[0]), _extract_version(entry[1])): entry
117+
(normalize_name(entry[0]), _extract_version(entry[1]), requirement(entry[1]).marker): entry
116118
for entry in sorted(
117119
parse_result.requirements,
118120
# Get the longest match and fallback to original WORKSPACE sorting,

python/private/pypi/pep508_env.bzl

Lines changed: 1 addition & 1 deletion
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

Lines changed: 78 additions & 0 deletions
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)