]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Avoid spurious errors when an imported version is consistent with pkg_resources 2499.avoid-spurious-version-errors.0 188/head
authorDaira Hopwood <daira@jacaranda.org>
Fri, 11 Sep 2015 23:59:51 +0000 (00:59 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Fri, 11 Sep 2015 23:59:51 +0000 (00:59 +0100)
but not parseable; also improve related error reporting. fixes ticket:2499

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/__init__.py
src/allmydata/test/test_version.py

index 0b0c5f816cc392920822cc1c496bf74cd15b812c..fa512a13a9860a1bd84986e7bbe0d0ee20f17487 100644 (file)
@@ -146,7 +146,8 @@ def get_platform():
 from allmydata.util import verlib
 def normalized_version(verstr, what=None):
     try:
-        return verlib.NormalizedVersion(verlib.suggest_normalized_version(verstr))
+        suggested = verlib.suggest_normalized_version(verstr) or verstr
+        return verlib.NormalizedVersion(suggested)
     except (StandardError, verlib.IrrationalVersionError):
         cls, value, trace = sys.exc_info()
         raise PackagingError, ("could not parse %s due to %s: %s"
@@ -351,6 +352,11 @@ def cross_check(pkg_resources_vers_and_locs, imported_vers_and_locs_list):
                               % (name, pr_ver, pr_loc, imp_comment))
                 continue
 
+            # If the pkg_resources version is identical to the imported version, don't attempt
+            # to normalize them, since it is unnecessary and may fail (ticket #2499).
+            if imp_ver != 'unknown' and pr_ver == imp_ver:
+                continue
+
             try:
                 pr_normver = normalized_version(pr_ver)
             except Exception, e:
index 7851f91ad38aa4d6c4048eab6f288727cafc440d..ee149b0e23ff856cc8e551345047e7de39523794 100644 (file)
@@ -91,17 +91,24 @@ class CheckRequirement(unittest.TestCase):
         self.failIfEqual(errors, [])
         self.failUnlessEqual([e for e in errors if "was not found by pkg_resources" not in e], [])
 
-    def test_cross_check_ticket_1355(self):
+    def test_cross_check_unparseable_versions(self):
         # The bug in #1355 is triggered when a version string from either pkg_resources or import
         # is not parseable at all by normalized_version.
 
         res = cross_check({"foo": ("unparseable", "")}, [("foo", ("1.0", "", None))])
         self.failUnlessEqual(len(res), 1)
         self.failUnlessIn("by pkg_resources could not be parsed", res[0])
+        self.failUnlessIn("due to IrrationalVersionError", res[0])
 
         res = cross_check({"foo": ("1.0", "")}, [("foo", ("unparseable", "", None))])
         self.failUnlessEqual(len(res), 1)
         self.failUnlessIn(") could not be parsed", res[0])
+        self.failUnlessIn("due to IrrationalVersionError", res[0])
+
+        # However, an error should not be triggered when the version strings are unparseable
+        # but equal (#2499).
+        res = cross_check({"foo": ("unparseable", "")}, [("foo", ("unparseable", "", None))])
+        self.failUnlessEqual(res, [])
 
     def test_cross_check(self):
         res = cross_check({}, [])
@@ -134,10 +141,18 @@ class CheckRequirement(unittest.TestCase):
         res = cross_check({"zope.interface": ("1.0", "")}, [("zope.interface", ("unknown", "", None))])
         self.failUnlessEqual(res, [])
 
+        res = cross_check({"zope.interface": ("unknown", "")}, [("zope.interface", ("unknown", "", None))])
+        self.failUnlessEqual(len(res), 1)
+        self.failUnlessIn("could not be parsed", res[0])
+
         res = cross_check({"foo": ("1.0", "")}, [("foo", ("unknown", "", None))])
         self.failUnlessEqual(len(res), 1)
         self.failUnlessIn("could not find a version number", res[0])
 
+        res = cross_check({"foo": ("unknown", "")}, [("foo", ("unknown", "", None))])
+        self.failUnlessEqual(len(res), 1)
+        self.failUnlessIn("could not be parsed", res[0])
+
         # When pkg_resources and import both find a package, there is only a warning if both
         # the version and the path fail to match.