From: david-sarah Date: Fri, 1 Apr 2011 20:27:50 +0000 (-0700) Subject: allmydata/__init__.py: Nicer reporting of unparseable version numbers in dependencies... X-Git-Url: https://git.rkrishnan.org/tahoe_css?a=commitdiff_plain;h=f3246a9ca013807ae6efab8b51ddd5483771337f;p=tahoe-lafs%2Ftahoe-lafs.git allmydata/__init__.py: Nicer reporting of unparseable version numbers in dependencies. fixes #1388 --- diff --git a/src/allmydata/__init__.py b/src/allmydata/__init__.py index 0eb5b245..b0e429fa 100644 --- a/src/allmydata/__init__.py +++ b/src/allmydata/__init__.py @@ -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,)) diff --git a/src/allmydata/test/test_version.py b/src/allmydata/test/test_version.py index 190bef81..1e7e3e34 100644 --- a/src/allmydata/test/test_version.py +++ b/src/allmydata/test/test_version.py @@ -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")})