annotate Lib/distutils/version.py @ 78069:a8aa77458e12 3.2

Add c_size_t and c_ssize_t to the ctypes summary table.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 12 Jul 2012 20:31:50 +0200
parents 9e4bb941a1ea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
1 #
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
2 # distutils/version.py
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
3 #
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
4 # Implements multiple version numbering conventions for the
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
5 # Python Module Distribution Utilities.
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
6 #
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
7 # $Id$
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
8 #
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
9
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
10 """Provides classes to represent module version numbers (one class for
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
11 each style of version numbering). There are currently two such classes
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
12 implemented: StrictVersion and LooseVersion.
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
13
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
14 Every version number class implements the following interface:
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
15 * the 'parse' method takes a string and parses it to some internal
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
16 representation; if the string is an invalid version number,
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
17 'parse' raises a ValueError exception
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
18 * the class constructor takes an optional string argument which,
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
19 if supplied, is passed to 'parse'
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
20 * __str__ reconstructs the string that was passed to 'parse' (or
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
21 an equivalent string -- ie. one that will generate an equivalent
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
22 version number instance)
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
23 * __repr__ generates Python code to recreate the version number instance
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
24 * _cmp compares the current instance with either another instance
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
25 of the same class or a string (which will be parsed to an instance
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
26 of the same class, thus must follow the same rules)
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
27 """
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
28
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 39644
diff changeset
29 import re
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
30
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
31 class Version:
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
32 """Abstract base class for version numbering classes. Just provides
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
33 constructor (__init__) and reproducer (__repr__), because those
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
34 seem to be the same for all version numbering classes; and route
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
35 rich comparisons to _cmp.
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
36 """
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
37
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
38 def __init__ (self, vstring=None):
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
39 if vstring:
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 13050
diff changeset
40 self.parse(vstring)
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
41
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
42 def __repr__ (self):
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 13050
diff changeset
43 return "%s ('%s')" % (self.__class__.__name__, str(self))
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
44
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
45 def __eq__(self, other):
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
46 c = self._cmp(other)
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
47 if c is NotImplemented:
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
48 return c
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
49 return c == 0
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
50
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
51 def __ne__(self, other):
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
52 c = self._cmp(other)
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
53 if c is NotImplemented:
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
54 return c
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
55 return c != 0
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
56
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
57 def __lt__(self, other):
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
58 c = self._cmp(other)
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
59 if c is NotImplemented:
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
60 return c
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
61 return c < 0
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
62
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
63 def __le__(self, other):
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
64 c = self._cmp(other)
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
65 if c is NotImplemented:
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
66 return c
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
67 return c <= 0
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
68
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
69 def __gt__(self, other):
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
70 c = self._cmp(other)
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
71 if c is NotImplemented:
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
72 return c
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
73 return c > 0
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
74
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
75 def __ge__(self, other):
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
76 c = self._cmp(other)
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
77 if c is NotImplemented:
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
78 return c
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
79 return c >= 0
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 26210
diff changeset
80
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
81
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
82 # Interface for version-number classes -- must be implemented
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
83 # by the following classes (the concrete ones -- Version should
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
84 # be treated as an abstract class).
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
85 # __init__ (string) - create and take same action as 'parse'
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
86 # (string parameter is optional)
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
87 # parse (string) - convert a string representation to whatever
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
88 # internal representation is appropriate for
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
89 # this style of version numbering
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
90 # __str__ (self) - convert back to a string; should be very similar
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
91 # (if not identical to) the string supplied to parse
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
92 # __repr__ (self) - generate Python code to recreate
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
93 # the instance
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
94 # _cmp (self, other) - compare two version numbers ('other' may
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
95 # be an unparsed version string, or another
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
96 # instance of your version class)
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
97
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
98
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
99 class StrictVersion (Version):
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
100
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
101 """Version numbering for anal retentives and software idealists.
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
102 Implements the standard interface for version number classes as
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
103 described above. A version number consists of two or three
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
104 dot-separated numeric components, with an optional "pre-release" tag
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
105 on the end. The pre-release tag consists of the letter 'a' or 'b'
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
106 followed by a number. If the numeric components of two version
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
107 numbers are equal, then one with a pre-release tag will always
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
108 be deemed earlier (lesser) than one without.
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
109
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
110 The following are valid version numbers (shown in the order that
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
111 would be obtained by sorting according to the supplied cmp function):
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
112
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
113 0.4 0.4.0 (these two are equivalent)
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
114 0.4.1
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
115 0.5a1
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
116 0.5b3
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
117 0.5
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
118 0.9.6
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
119 1.0
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
120 1.0.4a3
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
121 1.0.4b1
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
122 1.0.4
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
123
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
124 The following are examples of invalid version numbers:
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
125
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
126 1
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
127 2.7.2.2
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
128 1.3.a4
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
129 1.3pl1
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
130 1.3c4
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
131
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
132 The rationale for this version numbering system will be explained
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
133 in the distutils documentation.
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
134 """
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17129
diff changeset
135
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 13050
diff changeset
136 version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$',
48769
83b2d07b475b #2834: Change re module semantics, so that str and bytes mixing is forbidden,
Antoine Pitrou <solipsis@pitrou.net>
parents: 43026
diff changeset
137 re.VERBOSE | re.ASCII)
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
138
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
139
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
140 def parse (self, vstring):
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 13050
diff changeset
141 match = self.version_re.match(vstring)
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
142 if not match:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42299
diff changeset
143 raise ValueError("invalid version number '%s'" % vstring)
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
144
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
145 (major, minor, patch, prerelease, prerelease_num) = \
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 13050
diff changeset
146 match.group(1, 2, 4, 5, 6)
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
147
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
148 if patch:
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 39644
diff changeset
149 self.version = tuple(map(int, [major, minor, patch]))
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
150 else:
42142
a53e48be6df9 Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41480
diff changeset
151 self.version = tuple(map(int, [major, minor])) + (0,)
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
152
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
153 if prerelease:
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 39644
diff changeset
154 self.prerelease = (prerelease[0], int(prerelease_num))
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
155 else:
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
156 self.prerelease = None
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
157
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
158
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
159 def __str__ (self):
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17129
diff changeset
160
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
161 if self.version[2] == 0:
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 39644
diff changeset
162 vstring = '.'.join(map(str, self.version[0:2]))
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
163 else:
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 39644
diff changeset
164 vstring = '.'.join(map(str, self.version))
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
165
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
166 if self.prerelease:
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 13050
diff changeset
167 vstring = vstring + self.prerelease[0] + str(self.prerelease[1])
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
168
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
169 return vstring
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17129
diff changeset
170
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
171
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
172 def _cmp (self, other):
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 39644
diff changeset
173 if isinstance(other, str):
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 13050
diff changeset
174 other = StrictVersion(other)
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
175
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
176 if self.version != other.version:
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
177 # numeric versions don't match
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
178 # prerelease stuff doesn't matter
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
179 if self.version < other.version:
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
180 return -1
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
181 else:
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
182 return 1
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
183
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
184 # have to compare prerelease
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
185 # case 1: neither has prerelease; they're equal
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
186 # case 2: self has prerelease, other doesn't; other is greater
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
187 # case 3: self doesn't have prerelease, other does: self is greater
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
188 # case 4: both have prerelease: must compare them!
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
189
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
190 if (not self.prerelease and not other.prerelease):
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
191 return 0
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
192 elif (self.prerelease and not other.prerelease):
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
193 return -1
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
194 elif (not self.prerelease and other.prerelease):
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
195 return 1
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
196 elif (self.prerelease and other.prerelease):
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
197 if self.prerelease == other.prerelease:
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
198 return 0
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
199 elif self.prerelease < other.prerelease:
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
200 return -1
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
201 else:
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
202 return 1
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
203 else:
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
204 assert False, "never get here"
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
205
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
206 # end class StrictVersion
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
207
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
208
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
209 # The rules according to Greg Stein:
52432
9e4bb941a1ea Merged revisions 70707 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 51659
diff changeset
210 # 1) a version number has 1 or more numbers separated by a period or by
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
211 # sequences of letters. If only periods, then these are compared
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
212 # left-to-right to determine an ordering.
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
213 # 2) sequences of letters are part of the tuple for comparison and are
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
214 # compared lexicographically
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
215 # 3) recognize the numeric components may have leading zeroes
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17129
diff changeset
216 #
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
217 # The LooseVersion class below implements these rules: a version number
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
218 # string is split up into a tuple of integer and string components, and
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
219 # comparison is a simple tuple comparison. This means that version
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
220 # numbers behave in a predictable and obvious way, but a way that might
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
221 # not necessarily be how people *want* version numbers to behave. There
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
222 # wouldn't be a problem if people could stick to purely numeric version
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
223 # numbers: just split on period and compare the numbers as tuples.
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
224 # However, people insist on putting letters into their version numbers;
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
225 # the most common purpose seems to be:
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
226 # - indicating a "pre-release" version
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
227 # ('alpha', 'beta', 'a', 'b', 'pre', 'p')
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
228 # - indicating a post-release patch ('p', 'pl', 'patch')
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
229 # but of course this can't cover all version number schemes, and there's
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
230 # no way to know what a programmer means without asking him.
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17129
diff changeset
231 #
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
232 # The problem is what to do with letters (and other non-numeric
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
233 # characters) in a version number. The current implementation does the
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
234 # obvious and predictable thing: keep them as strings and compare
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
235 # lexically within a tuple comparison. This has the desired effect if
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
236 # an appended letter sequence implies something "post-release":
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
237 # eg. "0.99" < "0.99pl14" < "1.0", and "5.001" < "5.001m" < "5.002".
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
238 #
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
239 # However, if letters in a version number imply a pre-release version,
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
240 # the "obvious" thing isn't correct. Eg. you would expect that
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
241 # "1.5.1" < "1.5.2a2" < "1.5.2", but under the tuple/lexical comparison
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
242 # implemented here, this just isn't so.
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
243 #
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
244 # Two possible solutions come to mind. The first is to tie the
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
245 # comparison algorithm to a particular set of semantic rules, as has
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
246 # been done in the StrictVersion class above. This works great as long
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
247 # as everyone can go along with bondage and discipline. Hopefully a
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
248 # (large) subset of Python module programmers will agree that the
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
249 # particular flavour of bondage and discipline provided by StrictVersion
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
250 # provides enough benefit to be worth using, and will submit their
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
251 # version numbering scheme to its domination. The free-thinking
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
252 # anarchists in the lot will never give in, though, and something needs
13050
a195962e389c typos fixed by Rob Hooft
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 9654
diff changeset
253 # to be done to accommodate them.
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17129
diff changeset
254 #
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
255 # Perhaps a "moderately strict" version class could be implemented that
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
256 # lets almost anything slide (syntactically), and makes some heuristic
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
257 # assumptions about non-digits in version number strings. This could
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
258 # sink into special-case-hell, though; if I was as talented and
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
259 # idiosyncratic as Larry Wall, I'd go ahead and implement a class that
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
260 # somehow knows that "1.2.1" < "1.2.2a2" < "1.2.2" < "1.2.2pl3", and is
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
261 # just as happy dealing with things like "2g6" and "1.13++". I don't
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
262 # think I'm smart enough to do it right though.
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17129
diff changeset
263 #
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
264 # In any case, I've coded the test suite for this module (see
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
265 # ../test/test_version.py) specifically to fail on things like comparing
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
266 # "1.2a2" and "1.2". That's not because the *code* is doing anything
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
267 # wrong, it's because the simple, obvious design doesn't match my
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
268 # complicated, hairy expectations for real-world version numbers. It
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
269 # would be a snap to fix the test suite to say, "Yep, LooseVersion does
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
270 # the Right Thing" (ie. the code matches the conception). But I'd rather
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
271 # have a conception that matches common notions about version numbers.
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
272
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
273 class LooseVersion (Version):
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
274
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
275 """Version numbering for anarchists and software realists.
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
276 Implements the standard interface for version number classes as
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
277 described above. A version number consists of a series of numbers,
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
278 separated by either periods or strings of letters. When comparing
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
279 version numbers, the numeric components will be compared
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
280 numerically, and the alphabetic components lexically. The following
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
281 are all valid version numbers, in no particular order:
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
282
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
283 1.5.1
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
284 1.5.2b2
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
285 161
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
286 3.10a
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
287 8.02
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
288 3.4j
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
289 1996.07.12
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
290 3.2.pl0
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
291 3.1.1.6
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
292 2g6
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
293 11g
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
294 0.960923
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
295 2.2beta29
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
296 1.13++
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
297 5.5.kw
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
298 2.0b1pl0
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
299
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
300 In fact, there is no such thing as an invalid version number under
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
301 this scheme; the rules for comparison are simple and predictable,
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
302 but may not always give the results you want (for some definition
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
303 of "want").
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
304 """
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
305
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
306 component_re = re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE)
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
307
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
308 def __init__ (self, vstring=None):
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
309 if vstring:
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 13050
diff changeset
310 self.parse(vstring)
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
311
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
312
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
313 def parse (self, vstring):
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
314 # I've given up on thinking I can reconstruct the version string
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
315 # from the parsed tuple -- so I just store the string here for
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
316 # use by __str__
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
317 self.vstring = vstring
42299
c4ab3ef6194f Fix two bugs from the map->itertools.imap switch.
Collin Winter <collinw@gmail.com>
parents: 42142
diff changeset
318 components = [x for x in self.component_re.split(vstring)
c4ab3ef6194f Fix two bugs from the map->itertools.imap switch.
Collin Winter <collinw@gmail.com>
parents: 42142
diff changeset
319 if x and x != '.']
c4ab3ef6194f Fix two bugs from the map->itertools.imap switch.
Collin Winter <collinw@gmail.com>
parents: 42142
diff changeset
320 for i, obj in enumerate(components):
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
321 try:
42299
c4ab3ef6194f Fix two bugs from the map->itertools.imap switch.
Collin Winter <collinw@gmail.com>
parents: 42142
diff changeset
322 components[i] = int(obj)
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
323 except ValueError:
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
324 pass
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
325
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
326 self.version = components
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
327
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
328
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
329 def __str__ (self):
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
330 return self.vstring
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
331
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
332
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
333 def __repr__ (self):
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 13050
diff changeset
334 return "LooseVersion ('%s')" % str(self)
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
335
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
336
51122
adbd77a90bde Merged revisions 69025 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48769
diff changeset
337 def _cmp (self, other):
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 39644
diff changeset
338 if isinstance(other, str):
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 13050
diff changeset
339 other = LooseVersion(other)
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
340
51659
5dcaa2e1bc86 Merged revisions 69682 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 51122
diff changeset
341 if self.version == other.version:
5dcaa2e1bc86 Merged revisions 69682 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 51122
diff changeset
342 return 0
5dcaa2e1bc86 Merged revisions 69682 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 51122
diff changeset
343 if self.version < other.version:
5dcaa2e1bc86 Merged revisions 69682 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 51122
diff changeset
344 return -1
5dcaa2e1bc86 Merged revisions 69682 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 51122
diff changeset
345 if self.version > other.version:
5dcaa2e1bc86 Merged revisions 69682 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 51122
diff changeset
346 return 1
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 17129
diff changeset
347
9654
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
348
917357c12552 Initial checkin of distutils source files.
Greg Ward <gward@python.net>
parents:
diff changeset
349 # end class LooseVersion