Commits

Anonymous committed 3fe1afa

added the dev-post release

  • Participants
  • Parent commits cc93f5e
  • Branches tarek-postdev

Comments (0)

Files changed (1)

 discussion at PyCon 2009.
 
 >>> from verlib import RationalVersion as V
+
+
+>>> v = V('1.0')
+>>> str(v)
+'1.0'
+
+>>> v = V('1.1')
+>>> str(v)
+'1.1'
+
 >>> v = V('1.2.3')
 >>> str(v)
 '1.2.3'
 >>> V('1.2.0.0.0') == V('1.2')
 True
 
+>>> v = V('1.0.dev345')
+>>> str(v)
+'1.0.dev345'
+
+>>> v = V('1.0.dev456post623')
+>>> str(v)
+'1.0.dev456post623'
+
 # Irrational version strings
 
 >>> v = V('1')
 ...  > V('1.0.0a2') > V('1.0.0a1'))
 True
 
+>>> V('1.0') < V('1.0.dev456post623')
+True
+
+>>> V('1.0.dev456post623') < V('1.0.post456')
+True
+
 >>> (V('1.0a1')
 ...  < V('1.0a2.dev456')
 ...  < V('1.0a2')
 ...  < V('1.0c1')
 ...  < V('1.0.dev456')
 ...  < V('1.0')
+...  < V('1.0.dev456post623')  # development version of a post release
 ...  < V('1.0.post456'))
 True
 
 
     _version_re = re.compile(r'''
         ^
-        (\d+\.\d+)              # minimum 'N.N'
-        ((?:\.\d+)*)            # any number of extra '.N' segments
+        (?P<version>\d+\.\d+)              # minimum 'N.N'
+        (?P<extraversion>(?:\.\d+)*)            # any number of extra '.N' segments
         (?:
-          ([abc])               # 'a'=alpha, 'b'=beta, 'c'=release candidate
-          (\d+(?:\.\d+)*)
+          (?P<abc>[abc])               # 'a'=alpha, 'b'=beta, 'c'=release candidate
+          (?P<abcversion>\d+(?:\.\d+)*)
         )?
-        (\.(dev|post)(\d+))?    # pre- (aka development) and post-release tag
-        $
+        (?P<devpostmarker>\.((dev(?P<devpost1>\d+)post(?P<devpost2>\d+))|
+                             (dev(?P<dev>\d+))|
+                             (post(?P<post>\d+))))?
+       $
+    # A marker used in the second and third parts of the `info` tuple, for
         ''', re.VERBOSE)
-    # A marker used in the second and third parts of the `info` tuple, for
     # versions that don't have those segments, to sort properly. A example
     # of versions in sort order ('highest' last):
     #   1.0b1           ((1,0), ('b',1), ('f',))
     #   1.0.dev345      ((1,0), ('f',),  ('dev', 345))
     #   1.0             ((1,0), ('f',),  ('f',))
-    #   1.0.post345     ((1,0), ('f',),  ('post', 345))
+    #   1.0.post345     ((1,0), ('f',),  ('f', 'dev', 256, 'post', 345))
+    #   1.0.post345     ((1,0), ('f',),  ('f', 'post', 345))
     #                           ^        ^
     #   'f' < 'b' -------------/         |
     #                                    |
         match = self._version_re.search(s)
         if not match:
             raise IrrationalVersionError(s)
-        groups = match.groups()
+
+        groups = match.groupdict()
         parts = []
-        block = self._parse_numdots(groups[0], s, False, 2)
-        if groups[1]:
-            block += self._parse_numdots(groups[1][1:], s)
+        block = self._parse_numdots(groups['version'], s, False, 2)
+        extraversion = groups.get('extraversion')
+        if extraversion not in ('', None):
+            block += self._parse_numdots(extraversion[1:], s)
         parts.append(tuple(block))
-        if groups[2]:
-            block = [groups[2]]
-            block += self._parse_numdots(groups[3], s, pad_zeros_length=1)
+
+        abc = groups.get('abc')
+        if abc is not None:
+            block = [abc]
+            block += self._parse_numdots(groups.get('abcversion'), s,
+                                         pad_zeros_length=1)
             parts.append(tuple(block))
         else:
             parts.append(self._final_marker)
-        if groups[4]:
-            parts.append((groups[5], int(groups[6])))
+
+        if groups.get('devpostmarker') is not None:
+            dev = groups.get('dev')
+            post = groups.get('post')
+            if dev is not None:
+                parts.append(('dev', dev))
+            elif post is not None:
+                parts.append((self._final_marker[0], 'post', post))
+            else:
+                parts.append((self._final_marker[0],
+                              'dev', groups.get('devpost1'),
+                              'post', groups.get('devpost2')))
         else:
             parts.append(self._final_marker)
         self.info = tuple(parts)
         if error_on_huge_major_num and self.info[0][0] > 1980:
             raise HugeMajorVersionNumError("huge major version number, %r, "
                 "which might cause future problems: %r" % (self.info[0][0], s))
-        #print "_parse(%r) -> %r" % (s, self.info)
 
     def _parse_numdots(self, s, full_ver_str, drop_trailing_zeros=True,
             pad_zeros_length=0):
 
     def __str__(self):
         main, prerel, devpost = self.info
-        s = '.'.join(str(v) for v in main if v)
+        s = '.'.join(str(v) for v in main)# if v)
         if prerel is not self._final_marker:
             s += prerel[0]
-            s += '.'.join(str(v) for v in prerel[1:] if v)
+            s += '.'.join(str(v) for v in prerel[1:])# if v)
         if devpost is not self._final_marker:
-            s += '.' + ''.join(str(v) for v in prerel[1:] if v)
+            if devpost[0] == 'f':
+                devpost = devpost[1:]
+            s += '.' + ''.join(str(v) for v in devpost)# if v)
         return s
 
     def __repr__(self):