requirements fixer output is similar to pip freeze

This commit is contained in:
Vinay Karanam 2016-07-03 04:10:20 +05:30
parent 493665a5fc
commit c58ae08fed
2 changed files with 15 additions and 4 deletions

View file

@ -10,6 +10,19 @@ class Requirement(object):
self.value = None
self.comments = []
@property
def name(self):
if self.value is None:
return
if self.value == b'\n':
return
if self.value.startswith(b'-e '):
return self.value.lower().partition(b'=')[-1]
return self.value.lower().partition(b'==')[0]
def __lt__(self, requirement):
# \n means top of file comment, so always return True,
# otherwise just do a string comparison with value.
@ -18,10 +31,7 @@ class Requirement(object):
elif requirement.value == b'\n':
return False
else:
return (
self.value.lower().partition(b'==') <
requirement.value.lower().partition(b'==')
)
return self.name < requirement.name
def fix_requirements(f):

View file

@ -15,6 +15,7 @@ TESTS = (
(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'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'),
)