1VERSION = (2, 8, 0, 'final', 0) 2 3 4def get_version(): 5 "Returns a PEP 386-compliant version number from VERSION." 6 assert len(VERSION) == 5 7 assert VERSION[3] in ('alpha', 'beta', 'rc', 'final') 8 9 # Now build the two parts of the version number: 10 # main = X.Y[.Z] 11 # sub = .devN - for pre-alpha releases 12 # | {a|b|c}N - for alpha, beta and rc releases 13 14 parts = 2 if VERSION[2] == 0 else 3 15 main = '.'.join(str(x) for x in VERSION[:parts]) 16 17 sub = '' 18 if VERSION[3] != 'final': 19 mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'} 20 sub = mapping[VERSION[3]] + str(VERSION[4]) 21 22 return str(main + sub) 23