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"
% (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:
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({}, [])
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.