| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…-url (pre-commit#612) pip uses the first --index-url as the primary index and treats later --extra-index-url entries as additional indexes. If --extra-index-url sorts before --index-url (alphabetical order), the primary index URL is silently dropped. Keep --index-url ordered first. Fixes pre-commit#612.
| Back | FazBrowse Home | New Git URL |
Summary
Fixes #612 — requirements-txt-fixer sorts requirements alphabetically, which
reorders --index-url after --extra-index-url. That breaks pip: the primary
index URL is silently dropped because pip only honours the first
--index-url it sees.
Before
A requirements.txt written in the correct order:
was "fixed" (reordered) to:
With --extra-index-url first, pip drops the primary index URL.
After
--index-url is now always kept before --extra-index-url, matching pip's
expected semantics.
Root cause
In requirements_txt_fixer.py, each line (including --index-url and
--extra-index-url) is treated as a Requirement and sorted by name via
Requirement.__lt__. Since '--extra-index-url' < '--index-url'
alphabetically, the extra index ended up first.
Fix
Special-case the two options in Requirement.__lt__ so --index-url always
sorts before --extra-index-url. All other ordering (packages, comments,
duplicates) is unchanged.
Tests
Added two cases to tests/requirements_txt_fixer_test.py:
file rewritten).
Verification
two new cases).
reorder-python-imports, add-trailing-comma, autopep8).