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():
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,))
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")})