Fix python 3.x portability issue
cmp() as well as sorted(.., cmp=) does not exist in Python 3.x anymore. Convert to using sorted(..., key=) instead, which exists both in Python 2.x and Python 3.x. This isn't caught in CI because the code is entirely unused. Change-Id: I44a53291199c77d46c15beeff30b3c186f16cc64
This commit is contained in:
parent
0d954b03dd
commit
9928784a96
@ -32,19 +32,12 @@ _REQS_HEADER = [
|
||||
]
|
||||
|
||||
|
||||
def cmp_specifier(a, b):
|
||||
def key_specifier(a):
|
||||
weight = {'>=': 0, '>': 0,
|
||||
'==': 1, '~=': 1, '!=': 1,
|
||||
'===': 1, '==': 1, '~=': 1, '!=': 1,
|
||||
'<': 2, '<=': 2}
|
||||
a = a._spec
|
||||
b = b._spec
|
||||
wa, wb = weight[a[0]], weight[b[0]]
|
||||
res = cmp(wa, wb)
|
||||
if res != 0:
|
||||
return res
|
||||
else:
|
||||
return cmp(distutils.version.LooseVersion(a[1]),
|
||||
distutils.version.LooseVersion(b[1]))
|
||||
return (weight[a[0]], distutils.version.LooseVersion(a[1]))
|
||||
|
||||
|
||||
class Requirement(collections.namedtuple('Requirement',
|
||||
@ -68,7 +61,7 @@ class Requirement(collections.namedtuple('Requirement',
|
||||
if sort_specifiers:
|
||||
_specifiers = packaging.specifiers.SpecifierSet(specifiers)
|
||||
_specifiers = ['%s' % s for s in sorted(_specifiers,
|
||||
cmp=cmp_specifier)]
|
||||
key=key_specifier)]
|
||||
specifiers = ','.join(_specifiers)
|
||||
return '%s%s%s%s%s%s\n' % (location,
|
||||
package,
|
||||
|
Loading…
Reference in New Issue
Block a user