mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-05-15 13:40:37 +00:00
Fix requirements-txt-fixer ordering for index URLs
This commit is contained in:
parent
f1dff44d3a
commit
b3286e6e19
2 changed files with 20 additions and 1 deletions
|
|
@ -36,6 +36,15 @@ class Requirement:
|
|||
|
||||
return name[:m.start()]
|
||||
|
||||
@property
|
||||
def sort_key(self) -> tuple[int, bytes]:
|
||||
if self.name == b'--index-url':
|
||||
return (0, self.name)
|
||||
elif self.name == b'--extra-index-url':
|
||||
return (1, self.name)
|
||||
else:
|
||||
return (2, self.name)
|
||||
|
||||
def __lt__(self, requirement: Requirement) -> bool:
|
||||
# \n means top of file comment, so always return True,
|
||||
# otherwise just do a string comparison with value.
|
||||
|
|
@ -50,7 +59,7 @@ class Requirement:
|
|||
# with comments is kept)
|
||||
if self.name == requirement.name:
|
||||
return bool(self.comments) > bool(requirement.comments)
|
||||
return self.name < requirement.name
|
||||
return self.sort_key < requirement.sort_key
|
||||
|
||||
def is_complete(self) -> bool:
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue