-
-
Notifications
You must be signed in to change notification settings - Fork 588
fix: Resolve incorrect platform specific dependency #2766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Resolve incorrect platform specific dependency #2766
Conversation
e8ab944
to
ab105fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a CHANGELOG item for future reference?
e827a01
to
d3acfc0
Compare
These are just bugfixes to already merged code: * Fix nested bracket parsing in PEP508 marker parser. * Fix the sys_platform constants, which I noticed in bazel-contrib#2629 but they got also pointed out in bazel-contrib#2766. * Port some of python tests for requirement parsing and improve the implementation. Those tests will be removed in bazel-contrib#2629. * Move the platform related code to a separate file. All of the bug fixes have added tests. Work towards bazel-contrib#2423.
These are just bugfixes to already merged code: * Fix nested bracket parsing in PEP508 marker parser. * Fix the sys_platform constants, which I noticed in bazel-contrib#2629 but they got also pointed out in bazel-contrib#2766. * Port some of python tests for requirement parsing and improve the implementation. Those tests will be removed in bazel-contrib#2629. * Move the platform related code to a separate file. * Rename `pep508_req.bzl` to `pep508_requirement.bzl` to follow the convention. All of the bug fixes have added tests. Work towards bazel-contrib#2423.
@aignas is this good to, merge. It is currently a blocker for us |
These are just bugfixes to already merged code: * Fix nested bracket parsing in PEP508 marker parser. * Fix the sys_platform constants, which I noticed in #2629 but they got also pointed out in #2766. * Port some of python tests for requirement parsing and improve the implementation. Those tests will be removed in #2629. * Move the platform related code to a separate file. * Rename `pep508_req.bzl` to `pep508_requirement.bzl` to follow the convention. All of the bug fixes have added tests. Work towards #2423.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please also update the PR description to be more descriptive please? The PR template has good suggestions on how to structure it (i.e. the user visible change in behaviour should be explained).
Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
448d577
to
b11e59e
Compare
The improvements to the requirements utility are great, thank you! |
@aignas I am getting
Where should I be looking to fix this |
have same hashes so the repo name is thesame |
This change addresses a bug where
pip.parse
selects the wrong requirement entry when multiple extras are listed with platform-specific markers.🔍 Problem:
In a
requirements.txt
generated by tools likeuv
orpoetry
, it's valid to have multiple entries for the same package, each with different extras andsys_platform
markers, for example:The current implementation in
[parse_requirements.bzl](https://github.com/bazel-contrib/rules_python/blob/032f6aa738a673b13b605dabf55465c6fc1a56eb/python/private/pypi/parse_requirements.bzl#L114-L126)
uses a sort-by-length heuristic to select the “best” requirement when there are multiple entries with the same base name. This works well in legacyrequirements.txt
files where:...would indicate an intent to select the most specific subset of extras (i.e. the longest name).
However, this heuristic breaks in the presence of platform markers, where extras are not subsets, but distinct variants. In the example above, Bazel mistakenly selects
optimum[onnxruntime-gpu]
on macOS because it's a longer match, even though it is guarded by a Linux-only marker.✅ Fix:
This PR modifies the behavior to:
This ensures that only applicable requirements are considered during resolution, preserving correctness in multi-platform environments.
🧪 Before:
On macOS, the following entry is incorrectly selected:
✅ After:
Correct entry is selected:
close #2690