Show More
@@ -1,69 +1,36 b'' | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | """ |
|
2 | """ | |
3 | Utilities for version comparison |
|
3 | Utilities for version comparison | |
4 |
|
4 | |||
5 | It is a bit ridiculous that we need these. |
|
5 | It is a bit ridiculous that we need these. | |
6 | """ |
|
6 | """ | |
7 |
|
7 | |||
8 | #----------------------------------------------------------------------------- |
|
8 | #----------------------------------------------------------------------------- | |
9 | # Copyright (C) 2013 The IPython Development Team |
|
9 | # Copyright (C) 2013 The IPython Development Team | |
10 | # |
|
10 | # | |
11 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | # Distributed under the terms of the BSD License. The full license is in | |
12 | # the file COPYING, distributed as part of this software. |
|
12 | # the file COPYING, distributed as part of this software. | |
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 |
|
14 | |||
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | # Imports |
|
16 | # Imports | |
17 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
18 |
|
18 | |||
19 | from distutils.version import LooseVersion |
|
19 | from distutils.version import LooseVersion | |
20 |
|
20 | |||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Code |
|
22 | # Code | |
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 |
|
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 |
|
||||
57 | # |
|
|||
58 | def check_version(v, check): |
|
25 | def check_version(v, check): | |
59 | """check version string v >= check |
|
26 | """check version string v >= check | |
60 |
|
27 | |||
61 | If dev/prerelease tags result in TypeError for string-number comparison, |
|
28 | If dev/prerelease tags result in TypeError for string-number comparison, | |
62 | it is assumed that the dependency is satisfied. |
|
29 | it is assumed that the dependency is satisfied. | |
63 | Users on dev branches are responsible for keeping their own packages up to date. |
|
30 | Users on dev branches are responsible for keeping their own packages up to date. | |
64 | """ |
|
31 | """ | |
65 | try: |
|
32 | try: | |
66 | return LooseVersion(v) >= LooseVersion(check) |
|
33 | return LooseVersion(v) >= LooseVersion(check) | |
67 | except TypeError: |
|
34 | except TypeError: | |
68 | return True |
|
35 | return True | |
69 | No newline at end of file |
|
36 |
General Comments 0
You need to be logged in to leave comments.
Login now