Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pre_commit_hooks/requirements_txt_fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ def __lt__(self, requirement: Requirement) -> bool:
# with comments is kept)
if self.name == requirement.name:
return bool(self.comments) > bool(requirement.comments)
# `--index-url` must be ordered before `--extra-index-url`. pip
# uses the first `--index-url` as the primary index and treats
# subsequent `--extra-index-url` entries as additional indexes; if
# `--extra-index-url` appears first it is silently dropped, so we
# keep the index URL first (see issue #612).
if (
self.name == b'--index-url' and
requirement.name == b'--extra-index-url'
):
return True
if (
self.name == b'--extra-index-url' and
requirement.name == b'--index-url'
):
return False
return self.name < requirement.name

def is_complete(self) -> bool:
Expand Down
20 changes: 20 additions & 0 deletions tests/requirements_txt_fixer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@
PASS,
b'a=2.0.0 \\\n --hash=sha256:abcd\nb==1.0.0\n',
),
# `--index-url` must be kept before `--extra-index-url` so pip does
# not drop the primary index URL (see issue #612).
(
b'--index-url https://primary.example.com\n'
b'--extra-index-url https://extra.example.com\n'
b'foo==1.0\n',
PASS,
b'--index-url https://primary.example.com\n'
b'--extra-index-url https://extra.example.com\n'
b'foo==1.0\n',
),
(
b'--extra-index-url https://extra.example.com\n'
b'--index-url https://primary.example.com\n'
b'foo==1.0\n',
FAIL,
b'--index-url https://primary.example.com\n'
b'--extra-index-url https://extra.example.com\n'
b'foo==1.0\n',
),
),
)
def test_integration(input_s, expected_retval, output, tmpdir):
Expand Down
Loading