FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix requirements-txt-fixer reordering --index-url after --extra-index-url (#612) by sudorm-rf0 · Pull Request #1270 · pre-commit/pre-commit-hooks · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 15 additions & 0 deletions pre_commit_hooks/requirements_txt_fixer.py
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
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
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
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

Back | FazBrowse Home | New Git URL