[Python-checkins] distutils2: make sure project that have numbers in their names can be parsed

tarek.ziade python-checkins at python.org
Sat Jan 1 10:48:12 CET 2011


tarek.ziade pushed 0de7d5f4dae5 to distutils2:

http://hg.python.org/distutils2/rev/0de7d5f4dae5
changeset:   856:0de7d5f4dae5
tag:         tip
user:        Tarek Ziade <tarek at ziade.org>
date:        Sat Jan 01 10:47:44 2011 +0100
summary:
  make sure project that have numbers in their names can be parsed

files:
  distutils2/tests/test_version.py
  distutils2/version.py

diff --git a/distutils2/tests/test_version.py b/distutils2/tests/test_version.py
--- a/distutils2/tests/test_version.py
+++ b/distutils2/tests/test_version.py
@@ -201,6 +201,15 @@
         # XXX need to silent the micro version in this case
         #assert not VersionPredicate('Ho (<3.0,!=2.6)').match('2.6.3')
 
+
+        # Make sure a predicate that ends with a number works
+        self.assertTrue(VersionPredicate('virtualenv5 (1.0)').match('1.0'))
+        self.assertTrue(VersionPredicate('virtualenv5').match('1.0'))
+        self.assertTrue(VersionPredicate('vi5two').match('1.0'))
+        self.assertTrue(VersionPredicate('5two').match('1.0'))
+        self.assertTrue(VersionPredicate('vi5two 1.0').match('1.0'))
+        self.assertTrue(VersionPredicate('5two 1.0').match('1.0'))
+
         # test repr
         for predicate in predicates:
             self.assertEqual(str(VersionPredicate(predicate)), predicate)
diff --git a/distutils2/version.py b/distutils2/version.py
--- a/distutils2/version.py
+++ b/distutils2/version.py
@@ -322,7 +322,8 @@
     return None
 
 
-_PREDICATE = re.compile(r"(?i)^\s*([a-z_][\sa-zA-Z_-]*(?:\.[a-z_]\w*)*)(.*)")
+# A predicate is: "ProjectName (VERSION1, VERSION2, ..)
+_PREDICATE = re.compile(r"(?i)^\s*(\w[\s\w-]*(?:\.\w*)*)(.*)")
 _VERSIONS = re.compile(r"^\s*\((?P<versions>.*)\)\s*$|^\s*(?P<versions2>.*)\s*$")
 _PLAIN_VERSIONS = re.compile(r"^\s*(.*)\s*$")
 _SPLIT_CMP = re.compile(r"^\s*(<=|>=|<|>|!=|==)\s*([^\s,]+)\s*$")
@@ -359,19 +360,24 @@
         name, predicates = match.groups()
         self.name = name.strip()
         self.predicates = []
+        if predicates is None:
+            return
+
         predicates = _VERSIONS.match(predicates.strip())
-        if predicates is not None:
-            predicates = predicates.groupdict()
-            if predicates['versions'] is not None:
-                versions = predicates['versions']
-            else:
-                versions = predicates.get('versions2')
+        if predicates is None:
+            return
 
-            if versions is not None:
-                for version in versions.split(','):
-                    if version.strip() == '':
-                        continue
-                    self.predicates.append(_split_predicate(version))
+        predicates = predicates.groupdict()
+        if predicates['versions'] is not None:
+            versions = predicates['versions']
+        else:
+            versions = predicates.get('versions2')
+
+        if versions is not None:
+            for version in versions.split(','):
+                if version.strip() == '':
+                    continue
+                self.predicates.append(_split_predicate(version))
 
     def match(self, version):
         """Check if the provided version matches the predicates."""

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list