Fix requirements-txt-fixer reordering pip options#1249
Closed
Bahtya wants to merge 1 commit intopre-commit:mainfrom
Closed
Fix requirements-txt-fixer reordering pip options#1249Bahtya wants to merge 1 commit intopre-commit:mainfrom
Bahtya wants to merge 1 commit intopre-commit:mainfrom
Conversation
The requirements-txt-fixer was alphabetically sorting all lines, including pip options like --index-url and --extra-index-url. This caused --extra-index-url to be sorted above --index-url, breaking pip's index resolution order since --index-url must come first. Fix by preserving the original relative order of lines that start with `--` (pip options), while still sorting regular package requirements alphabetically. Closes pre-commit#612 Bahtya
Member
|
ai slop prs are not acceptable |
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.
Summary
Fixes #612
The
requirements-txt-fixerhook was alphabetically sorting all lines inrequirements.txt, including pip options like--index-urland--extra-index-url. This caused--extra-index-urlto be sorted above--index-url(since "extra" < "index" alphabetically), which breaks pip's index resolution order.Changes
pre_commit_hooks/requirements_txt_fixer.py: Added a check inRequirement.__lt__so that when both requirements being compared start with--(i.e., are pip options), they maintain their original relative order instead of being sorted alphabetically. Regular package requirements continue to be sorted alphabetically.tests/requirements_txt_fixer_test.py: Added 3 test cases:--index-urlbefore--extra-index-urlstays in order (PASS)--extra-index-urlbefore--index-urlstays in order (PASS, original order preserved)Test plan
--index-url/--extra-index-urlordering is preservedBahtya