go/tools/builders: don't format subcommand output as []byte#2766
Merged
jayconrod merged 1 commit intobazel-contrib:masterfrom Dec 22, 2020
Merged
go/tools/builders: don't format subcommand output as []byte#2766jayconrod merged 1 commit intobazel-contrib:masterfrom
jayconrod merged 1 commit intobazel-contrib:masterfrom
Conversation
Use os.Stderr.Write instead of fmt.Fprint. The latter formats the value as a []byte, not a string. (This was due to my own bad review comment on bazel-contrib#2736. Sorry.)
jayconrod
pushed a commit
that referenced
this pull request
Dec 23, 2020
Use os.Stderr.Write instead of fmt.Fprint. The latter formats the value as a []byte, not a string. (This was due to my own bad review comment on #2736. Sorry.)
jayconrod
pushed a commit
that referenced
this pull request
Dec 23, 2020
Use os.Stderr.Write instead of fmt.Fprint. The latter formats the value as a []byte, not a string. (This was due to my own bad review comment on #2736. Sorry.)
yushan26
pushed a commit
to yushan26/rules_go
that referenced
this pull request
Jun 16, 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.
yushan26
pushed a commit
to yushan26/rules_go
that referenced
this pull request
Jun 16, 2025
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 like `uv` or `poetry`, it's valid to have multiple entries for the same package, each with different extras and `sys_platform` markers, for example: ```ini optimum[onnxruntime]==1.17.1 ; sys_platform == 'darwin' optimum[onnxruntime-gpu]==1.17.1 ; sys_platform == 'linux' ``` The current implementation in [`[parse_requirements.bzl](https://github.com/bazel-contrib/rules_python/blob/032f6aa738a673b13b605dabf55465c6fc1a56eb/python/private/pypi/parse_requirements.bzl#L114-L126)`](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 legacy `requirements.txt` files where: ``` my_dep my_dep[foo] my_dep[foo,bar] ``` ...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: 1. **Add the requirement marker** as part of the sorting key. 2. **Then apply the longest-match logic** to drop duplicate requirements with different extras but the same markers. 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: ``` optimum[onnxruntime-gpu]==1.17.1 ; sys_platform == 'linux' ``` #### ✅ After: Correct entry is selected: ``` optimum[onnxruntime]==1.17.1 ; sys_platform == 'darwin' ``` close bazel-contrib/rules_python#2690 --------- Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
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.
Use os.Stderr.Write instead of fmt.Fprint. The latter formats the
value as a []byte, not a string.
(This was due to my own bad review comment on #2736. Sorry.)