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 #612
Bahtya
Summary
Fixes #612
The requirements-txt-fixer hook was alphabetically sorting all lines in requirements.txt, including pip options like --index-url and --extra-index-url. This caused --extra-index-url to 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 in Requirement.__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:
Test plan
Bahtya