allmydata/__init__.py: Nicer reporting of unparseable version numbers in dependencies. fixes #1388

This commit is contained in:
david-sarah 2011-04-01 13:27:50 -07:00
parent 2b9d333835
commit f3246a9ca0
2 changed files with 18 additions and 5 deletions

View 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,))

View 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")})