Commits

Thomas Waldmann  committed ca7580c

use PEP386 strict version numbers

  • Participants
  • Parent commits b55d079

Comments (0)

Files changed (3)

File MoinMoin/__init__.py

 
 from MoinMoin.util.version import Version
 
-version = Version(2, 0, 0, 'alpha')
+version = Version(2, 0, 0, 'a0')
 

File MoinMoin/util/_tests/test_version.py

         assert Version(1, 2, 3).major == 1
         assert Version(1, 2, 3).minor == 2
         assert Version(1, 2, 3).release == 3
-        assert Version(1, 2, 3, '4.5alpha6').additional == '4.5alpha6'
+        assert Version(1, 2, 3, 'a4').additional == 'a4'
         # test Version init and Version to str conversion
         assert str(Version(1)) == "1.0.0"
         assert str(Version(1, 2)) == "1.2.0"
         assert str(Version(1, 2, 3)) == "1.2.3"
-        assert str(Version(1, 2, 3, '4.5alpha6')) == "1.2.3-4.5alpha6"
+        assert str(Version(1, 2, 3, 'a4')) == "1.2.3a4"
         assert str(Version(version='1.2.3')) == "1.2.3"
-        assert str(Version(version='1.2.3-4.5alpha6')) == "1.2.3-4.5alpha6"
+        assert str(Version(version='1.2.3a4')) == "1.2.3a4"
         # test Version comparison, trivial cases
         assert Version() == Version()
         assert Version(1) == Version(1)
         assert Version(1, 2) == Version(1, 2)
         assert Version(1, 2, 3) == Version(1, 2, 3)
-        assert Version(1, 2, 3, 'foo') == Version(1, 2, 3, 'foo')
+        assert Version(1, 2, 3, 'a4') == Version(1, 2, 3, 'a4')
         assert Version(1) != Version(2)
         assert Version(1, 2) != Version(1, 3)
         assert Version(1, 2, 3) != Version(1, 2, 4)
-        assert Version(1, 2, 3, 'foo') != Version(1, 2, 3, 'bar')
+        assert Version(1, 2, 3, 'a4') != Version(1, 2, 3, 'a5')
         assert Version(1) < Version(2)
         assert Version(1, 2) < Version(1, 3)
         assert Version(1, 2, 3) < Version(1, 2, 4)
-        assert Version(1, 2, 3, 'bar') < Version(1, 2, 3, 'foo')
+        assert Version(1, 2, 3, 'a4') < Version(1, 2, 3, 'a5')
+        assert Version(1, 2, 3, 'b4') < Version(1, 2, 3, 'b5')
+        assert Version(1, 2, 3, 'c4') < Version(1, 2, 3, 'c5')
         assert Version(2) > Version(1)
         assert Version(1, 3) > Version(1, 2)
         assert Version(1, 2, 4) > Version(1, 2, 3)
-        assert Version(1, 2, 3, 'foo') > Version(1, 2, 3, 'bar')
+        assert Version(1, 2, 3, 'b1') > Version(1, 2, 3, 'a1')
+        assert Version(1, 2, 3, 'c1') > Version(1, 2, 3, 'b1')
         # test Version comparison, more delicate cases
+        assert Version(1, 2, 3) > Version(1, 2, 3, 'c1')
         assert Version(1, 12) > Version(1, 9)
         assert Version(1, 12) > Version(1, 1, 2)
-        assert Version(1, 0, 0, '0.0a2') > Version(1, 0, 0, '0.0a1')
-        assert Version(1, 0, 0, '0.0b1') > Version(1, 0, 0, '0.0a9')
-        assert Version(1, 0, 0, '0.0b2') > Version(1, 0, 0, '0.0b1')
-        assert Version(1, 0, 0, '0.0c1') > Version(1, 0, 0, '0.0b9')
-        assert Version(1, 0, 0, '1') > Version(1, 0, 0, '0.0c9')
         # test Version playing nice with tuples
-        assert Version(1, 2, 3) == (1, 2, 3, '')
+        assert Version(1, 2, 3) < (1, 2, 4)
+        assert Version(1, 2, 3, 'c99') < (1, 2, 4)
         assert Version(1, 2, 4) > (1, 2, 3)
+        assert Version(1, 2, 4) > (1, 2, 3, 'c99')
 
 
 coverage_modules = ['MoinMoin.util.version']

File MoinMoin/util/version.py

 
 class Version(tuple):
     """
-    Version objects store versions like 1.2.3-4.5alpha6 in a structured
+    Version objects store versions like 1.2.3a4 in a structured
     way and support version comparisons and direct version component access.
     1: major version (digits only)
     2: minor version (digits only)
     3: (maintenance) release version (digits only)
-    4.5alpha6: optional additional version specification (str)
+    a4: optional additional version specification (str)
+
+    See PEP386 for more details.
+    TODO: use 3rd party code for PEP386 version numbers later.
 
     You can create a Version instance either by giving the components, like:
-        Version(1,2,3,'4.5alpha6')
+        Version(1,2,3,'a4')
     or by giving the composite version string, like:
-        Version(version="1.2.3-4.5alpha6").
+        Version(version="1.2.3a4").
 
     Version subclasses tuple, so comparisons to tuples should work.
     Also, we inherit all the comparison logic from tuple base class.
             (?P<minor>\d+)
             \.
             (?P<release>\d+)
-            (-
-             (?P<additional>.+)
-            )?""",
+            (?P<additional>[abc]\d+)?""",
             re.VERBOSE)
 
     @classmethod
         if match is None:
             raise ValueError("Unexpected version string format: %r" % version)
         v = match.groupdict()
-        return int(v['major']), int(v['minor']), int(v['release']), str(v['additional'] or '')
+        return int(v['major']), int(v['minor']), int(v['release']), str(v['additional'] or 'd0')
 
-    def __new__(cls, major=0, minor=0, release=0, additional='', version=None):
+    def __new__(cls, major=0, minor=0, release=0, additional='d0', version=None):
+        # HACK: Use "d0" for release, as "d0" > "c99".
         if version:
             major, minor, release, additional = cls.parse_version(version)
         return tuple.__new__(cls, (major, minor, release, additional))
     major = property(lambda self: self[0])
     minor = property(lambda self: self[1])
     release = property(lambda self: self[2])
-    additional = property(lambda self: self[3])
+    additional = property(lambda self: self[3] if self[3] != 'd0' else '')
 
     def __str__(self):
         version_str = "%d.%d.%d" % (self.major, self.minor, self.release)
-        if self.additional:
-            version_str += "-%s" % self.additional
+        if self.additional != 'd0':
+            version_str += self.additional
         return version_str