Show More
@@ -0,0 +1,56 b'' | |||
|
1 | # encoding: utf-8 | |
|
2 | """ | |
|
3 | Utilities for version comparison | |
|
4 | ||
|
5 | It is a bit ridiculous that we need these. | |
|
6 | """ | |
|
7 | ||
|
8 | #----------------------------------------------------------------------------- | |
|
9 | # Copyright (C) 2013 The IPython Development Team | |
|
10 | # | |
|
11 | # Distributed under the terms of the BSD License. The full license is in | |
|
12 | # the file COPYING, distributed as part of this software. | |
|
13 | #----------------------------------------------------------------------------- | |
|
14 | ||
|
15 | #----------------------------------------------------------------------------- | |
|
16 | # Imports | |
|
17 | #----------------------------------------------------------------------------- | |
|
18 | ||
|
19 | from distutils.version import LooseVersion | |
|
20 | ||
|
21 | #----------------------------------------------------------------------------- | |
|
22 | # Code | |
|
23 | #----------------------------------------------------------------------------- | |
|
24 | ||
|
25 | class NumericalVersion(LooseVersion): | |
|
26 | """A version of LooseVersion that is *always* comparable | |
|
27 | ||
|
28 | String elements (of any kind!) are interpreted as infinite. | |
|
29 | Since these are generally only on development branches, | |
|
30 | that is fairly safe, even though technically 1.0a1 should be less than 1.0. | |
|
31 | """ | |
|
32 | def parse (self, vstring): | |
|
33 | # I've given up on thinking I can reconstruct the version string | |
|
34 | # from the parsed tuple -- so I just store the string here for | |
|
35 | # use by __str__ | |
|
36 | self.vstring = vstring | |
|
37 | components = filter(lambda x: x and x != '.', | |
|
38 | self.component_re.split(vstring)) | |
|
39 | for i in range(len(components)): | |
|
40 | try: | |
|
41 | components[i] = int(components[i]) | |
|
42 | except ValueError: | |
|
43 | # this is the only change | |
|
44 | components[i] = float('inf') | |
|
45 | ||
|
46 | self.version = components | |
|
47 | ||
|
48 | def version_tuple(vs): | |
|
49 | """Return a tuple of numbers from a version string. | |
|
50 | ||
|
51 | 'dev' 'a', 'etc' are transformed to float('inf'), | |
|
52 | so they will always compare positively to any | |
|
53 | regular integer element. | |
|
54 | """ | |
|
55 | return tuple(NumericalVersion(vs).version) | |
|
56 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now