[Python-checkins] distutils2: allowing predicates without parenthesis -- that's how the install script will
tarek.ziade
python-checkins at python.org
Sat Jan 1 10:06:37 CET 2011
tarek.ziade pushed edb34bfee375 to distutils2:
http://hg.python.org/distutils2/rev/edb34bfee375
changeset: 853:edb34bfee375
tag: tip
user: Tarek Ziade <tarek at ziade.org>
date: Sat Jan 01 10:05:56 2011 +0100
summary:
allowing predicates without parenthesis -- that's how the install script will work
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
@@ -196,6 +196,8 @@
self.assertRaises(ValueError, VersionPredicate, '')
+ self.assertTrue(VersionPredicate('Hey 2.5').match('2.5.1'))
+
# XXX need to silent the micro version in this case
#assert not VersionPredicate('Ho (<3.0,!=2.6)').match('2.6.3')
@@ -220,6 +222,7 @@
for version in other_versions:
self.assertFalse(V(version).is_final)
+
class VersionWhiteBoxTestCase(unittest.TestCase):
def test_parse_numdots(self):
diff --git a/distutils2/version.py b/distutils2/version.py
--- a/distutils2/version.py
+++ b/distutils2/version.py
@@ -323,7 +323,7 @@
_PREDICATE = re.compile(r"(?i)^\s*([a-z_][\sa-zA-Z_-]*(?:\.[a-z_]\w*)*)(.*)")
-_VERSIONS = re.compile(r"^\s*\((.*)\)\s*$")
+_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*$")
@@ -358,14 +358,20 @@
name, predicates = match.groups()
self.name = name.strip()
- predicates = predicates.strip()
- predicates = _VERSIONS.match(predicates)
+ self.predicates = []
+ predicates = _VERSIONS.match(predicates.strip())
if predicates is not None:
- predicates = predicates.groups()[0]
- self.predicates = [_split_predicate(pred.strip())
- for pred in predicates.split(',')]
- else:
- self.predicates = []
+ 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