]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
allmydata/__init__.py: Nicer reporting of unparseable version numbers in dependencies...
authordavid-sarah <david-sarah@jacaranda.org>
Fri, 1 Apr 2011 20:27:50 +0000 (13:27 -0700)
committerdavid-sarah <david-sarah@jacaranda.org>
Fri, 1 Apr 2011 20:27:50 +0000 (13:27 -0700)
src/allmydata/__init__.py
src/allmydata/test/test_version.py

index 0eb5b245e9e88d8ad9ca17db9fbd14d80eaf204b..b0e429face3b06bcc528401fa75ba7c27da7f0e9 100644 (file)
@@ -133,8 +133,13 @@ def get_platform():
 
 
 from allmydata.util import verlib
-def normalized_version(verstr):
-    return verlib.NormalizedVersion(verlib.suggest_normalized_version(verstr))
+def normalized_version(verstr, what=None):
+    try:
+        return verlib.NormalizedVersion(verlib.suggest_normalized_version(verstr))
+    except (StandardError, verlib.IrrationalVersionError), e:
+        cls, value, traceback = sys.exc_info()
+        raise PackagingError, ("could not parse %s due to %s: %s"
+                               % (what or repr(verstr), cls.__name__, value)), traceback
 
 
 def get_package_versions_and_locations():
@@ -217,19 +222,19 @@ def check_requirement(req, vers_and_locs):
         raise ImportError("could not import %r for requirement %r" % (comment, req))
     if actual == 'unknown':
         return
-    actualver = normalized_version(actual)
+    actualver = normalized_version(actual, what="actual version %r of %s from %r" % (actual, name, location))
 
     for r in reqlist:
         s = r.split('>=')
         if len(s) == 2:
             required = s[1].strip(' ')
-            if actualver >= normalized_version(required):
+            if actualver >= normalized_version(required, what="required minimum version %r in %r" % (required, req)):
                 return  # minimum requirement met
         else:
             s = r.split('==')
             if len(s) == 2:
                 required = s[1].strip(' ')
-                if actualver == normalized_version(required):
+                if actualver == normalized_version(required, what="required exact version %r in %r" % (required, req)):
                     return  # exact requirement met
             else:
                 raise PackagingError("no version info or could not understand requirement %r" % (req,))
index 190bef811a044b0ffffc0073b0431d0b1749a72a..1e7e3e34fa2231c68322160e24a849a4bde3a484 100644 (file)
@@ -20,12 +20,20 @@ class CheckRequirement(unittest.TestCase):
 
         check_requirement("foolscap[secure_connections] >= 0.6.0", {"foolscap": ("0.7.0", "", None)})
 
+        try:
+            check_requirement("foolscap[secure_connections] >= 0.6.0", {"foolscap": ("0.6.1+", "", None)})
+            # succeeding is ok
+        except PackagingError, e:
+            self.failUnlessIn("could not parse", str(e))
+
         self.failUnlessRaises(PackagingError, check_requirement,
                               "foolscap[secure_connections] >= 0.6.0", {"foolscap": ("0.5.1", "", None)})
         self.failUnlessRaises(PackagingError, check_requirement,
                               "pycrypto == 2.0.1, == 2.1, >= 2.3", {"pycrypto": ("2.2.0", "", None)})
         self.failUnlessRaises(PackagingError, check_requirement,
                               "foo >= 1.0", {})
+        self.failUnlessRaises(PackagingError, check_requirement,
+                              "foo >= 1.0", {"foo": ("irrational", "", None)})
 
         self.failUnlessRaises(ImportError, check_requirement,
                               "foo >= 1.0", {"foo": (None, None, "foomodule")})