fix: Resolve incorrect platform specific dependency#2766
Merged
aignas merged 2 commits intobazel-contrib:mainfrom Apr 11, 2025
Merged
fix: Resolve incorrect platform specific dependency#2766aignas merged 2 commits intobazel-contrib:mainfrom
aignas merged 2 commits intobazel-contrib:mainfrom
Conversation
e8ab944 to
ab105fd
Compare
ewianda
commented
Apr 10, 2025
aignas
reviewed
Apr 10, 2025
Collaborator
aignas
left a comment
There was a problem hiding this comment.
Could you please add a CHANGELOG item for future reference?
e827a01 to
d3acfc0
Compare
aignas
added a commit
to aignas/rules_python
that referenced
this pull request
Apr 10, 2025
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.
aignas
added a commit
to aignas/rules_python
that referenced
this pull request
Apr 10, 2025
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.
Contributor
Author
|
@aignas is this good to, merge. It is currently a blocker for us |
github-merge-queue bot
pushed a commit
that referenced
this pull request
Apr 10, 2025
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.
aignas
reviewed
Apr 11, 2025
Collaborator
aignas
left a comment
There was a problem hiding this comment.
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
aignas
approved these changes
Apr 11, 2025
Collaborator
|
The improvements to the requirements utility are great, thank you! |
Contributor
Author
|
@aignas I am getting Where should I be looking to fix this |
Contributor
Author
|
have same hashes so the repo name is thesame |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change addresses a bug where
pip.parseselects the wrong requirement entry when multiple extras are listed with platform-specific markers.🔍 Problem:
In a
requirements.txtgenerated by tools likeuvorpoetry, it's valid to have multiple entries for the same package, each with different extras andsys_platformmarkers, 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.txtfiles 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