1. PyPA
  2. Python Packaging Authority Projects
  3. distlib

Commits

Vinay Sajip  committed ff84b98

Added local component to version.

  • Participants
  • Parent commits a8f33bc
  • Branches default

Comments (0)

Files changed (2)

File distlib/version.py

View file
 
 
 PEP426_VERSION_RE = re.compile(r'^(\d+\.\d+(\.\d+)*)((a|b|c|rc)(\d+))?'
-                               r'(\.(post)(\d+))?(\.(dev)(\d+))?$')
+                               r'(\.(post)(\d+))?(\.(dev)(\d+))?'
+                               r'(-(\d+(\.\d+)?))?$')
 
 
 def _pep426_key(s):
     pre = groups[3:5]
     post = groups[6:8]
     dev = groups[9:11]
+    local = groups[12]
     if pre == (None, None):
         pre = ()
     else:
         dev = ()
     else:
         dev = dev[0], int(dev[1])
+    if local is None:
+        local = ()
+    else:
+        local = tuple([int(s) for s in local.split('.')])
     if not pre:
         # either before pre-release, or final release and after
         if not post and dev:
         dev = ('final',)
 
     #print('%s -> %s' % (s, m.groups()))
-    return nums, pre, post, dev
+    return nums, pre, post, dev, local
 
 
 _normalized_key = _pep426_key
 
     @property
     def is_prerelease(self):
-        return any(t[0] in self.PREREL_TAGS for t in self._parts)
+        return any(t[0] in self.PREREL_TAGS for t in self._parts if t)
 
 
 def _match_prefix(x, y):

File tests/test_version.py

View file
                 #(NV('1.2.3.4.0b3', drop_trailing_zeros=True), '1.2.3.4b3'),
                 #(NV('1.2.0.0.0', drop_trailing_zeros=True), '1.2'),
                 (NV('1.0.dev345'), '1.0.dev345'),
-                (NV('1.0.post456.dev623'), '1.0.post456.dev623'))
+                (NV('1.0.post456.dev623'), '1.0.post456.dev623'),
+                (NV('1.2.3-1.2'), '1.2.3-1.2'),
+               )
 
     def test_repr(self):
         self.assertEqual(repr(NV('1.0')), "NormalizedVersion('1.0')")
         unsupported = ('1', '1.2a', '1.2.3b',
                       #'1.02', '1.2a03', '1.2a3.04',
                       '1.2.dev.2', '1.2dev', '1.2.dev',
+                      '1.2-', '1.2-a',
                       '1.2.dev2.post2', '1.2.post2.dev3.post4')
 
         for s in unsupported:
             self.assertRaises(UnsupportedVersionError, NV, s)
 
     def test_huge_version(self):
-        raise unittest.SkipTest('Test disabled for now')
         self.assertEqual(str(NV('1980.0')), '1980.0')
 
     def test_comparison(self):
         ...  < NV('1.0b2')
         ...  < NV('1.0c1.dev456')
         ...  < NV('1.0c1')
+        ...  < NV('1.0c1-1')
+        ...  < NV('1.0c1-1.1')
         ...  < NV('1.0.dev7')
         ...  < NV('1.0.dev18')
         ...  < NV('1.0.dev456')
         ...  < NV('1.0rc1')
         ...  < NV('1.0rc2')
         ...  < NV('1.0')
+        ...  < NV('1.0-1')
+        ...  < NV('1.0-1.1')
         ...  < NV('1.0.post456.dev623')  # development version of a post release
-        ...  < NV('1.0.post456'))
+        ...  < NV('1.0.post456.dev623-1')
+        ...  < NV('1.0.post456.dev623-1.1')
+        ...  < NV('1.0.post456')
+             < NV('1.0.post456-1')
+             < NV('1.0.post456-1.1'))
         True
         """
         doctest.script_from_examples(comparison_doctest_string)
             '1.0rc1',
             '1.0.post345.dev456',
             '1.1.dev1',
+            '1.1.dev1-1.2',
         )
         final_releases = (
             '1.0',
             '1.0.post345',
+            '1.0.post345-2.3',
         )
         for s in pre_releases:
             self.assertTrue(NV(s).is_prerelease)