Permalink
Browse files

Fix rc build comparison via natural cmp helper.

  • Loading branch information...
1 parent ee1919e commit e9e436fe222b8afd939ccc46681f970471e4f2f6 @kxepal committed Feb 8, 2012
Showing with 7 additions and 1 deletion.
  1. +7 −1 semver.py
View
@@ -26,9 +26,15 @@ def parse(version):
def compare(ver1, ver2):
+ def nat_cmp(a, b):
+ a, b = a and str(a) or '', b and str(b) or ''
+ convert = lambda text: int(text) if text.isdigit() else text.lower()
+ alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
+ return cmp(alphanum_key(a), alphanum_key(b))
+
def compare_by_keys(d1, d2, keys):
for key in keys:
- v = cmp(d1.get(key), d2.get(key))
+ v = nat_cmp(d1.get(key), d2.get(key))
if v != 0:
return v
return 0

0 comments on commit e9e436f

Please sign in to comment.