Created
September 30, 2015 21:39
-
-
Save lukeyeager/9922a2229f7a03d1463c to your computer and use it in GitHub Desktop.
Nobody sorts semantic versions correctly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import distutils.version | |
import pkg_resources | |
import random | |
import semantic_version | |
import sys | |
versions = sys.argv[1:] | |
if not versions: | |
versions = 'v1.0.0-alpha v1.0.0-alpha.1 v1.0.0-alpha.beta v1.0.0-beta v1.0.0-beta.2 v1.0.0-beta.11 v1.0.0-rc.1 v1.0 v1.0.0 v1.0.1 v1.0.2'.split() | |
random.shuffle(versions) | |
def semver_key(version): | |
try: | |
return semantic_version.Version(version.strip('v')) | |
except ValueError: | |
return semantic_version.Version(version.strip('v'), partial=True) | |
strings = sorted(versions) | |
distutils = sorted(versions, key=distutils.version.LooseVersion) | |
setuptools = sorted(versions, key=pkg_resources.parse_version) | |
semver = sorted(versions, key=semver_key) | |
fmt = '%-19s%-32s%-29s%s' | |
print fmt % ('str', 'distutils.version.LooseVersion', 'pkg_resources.parse_version', 'semantic_version.Version') | |
for lst in zip(strings, distutils, setuptools, semver): | |
print fmt % lst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compare with http://semver.org/: