mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-07 12:26:52 +00:00
Merge pull request #127 from vinayinvicible/requirements
handle editable requirements properly
This commit is contained in:
commit
3fa0265235
2 changed files with 9 additions and 4 deletions
|
|
@ -10,6 +10,13 @@ class Requirement(object):
|
||||||
self.value = None
|
self.value = None
|
||||||
self.comments = []
|
self.comments = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
if self.value.startswith(b'-e '):
|
||||||
|
return self.value.lower().partition(b'=')[-1]
|
||||||
|
|
||||||
|
return self.value.lower().partition(b'==')[0]
|
||||||
|
|
||||||
def __lt__(self, requirement):
|
def __lt__(self, requirement):
|
||||||
# \n means top of file comment, so always return True,
|
# \n means top of file comment, so always return True,
|
||||||
# otherwise just do a string comparison with value.
|
# otherwise just do a string comparison with value.
|
||||||
|
|
@ -18,10 +25,7 @@ class Requirement(object):
|
||||||
elif requirement.value == b'\n':
|
elif requirement.value == b'\n':
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return (
|
return self.name < requirement.name
|
||||||
self.value.lower().partition(b'==') <
|
|
||||||
requirement.value.lower().partition(b'==')
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def fix_requirements(f):
|
def fix_requirements(f):
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ TESTS = (
|
||||||
(b'\nbar\nfoo\n', 0, b'\nbar\nfoo\n'),
|
(b'\nbar\nfoo\n', 0, b'\nbar\nfoo\n'),
|
||||||
(b'pyramid==1\npyramid-foo==2\n', 0, b'pyramid==1\npyramid-foo==2\n'),
|
(b'pyramid==1\npyramid-foo==2\n', 0, b'pyramid==1\npyramid-foo==2\n'),
|
||||||
(b'ocflib\nDjango\nPyMySQL\n', 1, b'Django\nocflib\nPyMySQL\n'),
|
(b'ocflib\nDjango\nPyMySQL\n', 1, b'Django\nocflib\nPyMySQL\n'),
|
||||||
|
(b'-e git+ssh://git_url@tag#egg=ocflib\nDjango\nPyMySQL\n', 1, b'Django\n-e git+ssh://git_url@tag#egg=ocflib\nPyMySQL\n'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue