mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-11 23:42:38 +00:00
allmydata/__init__.py: preserve the message and last traceback entry (file, line number, function, and source line) of ImportErrors in the package versions string. fixes #1389
This commit is contained in:
parent
4911510e0d
commit
449b7ad8c7
@ -32,7 +32,7 @@ except ImportError:
|
|||||||
# http://allmydata.org/trac/tahoe/wiki/Versioning
|
# http://allmydata.org/trac/tahoe/wiki/Versioning
|
||||||
__full_version__ = __appname__ + '/' + str(__version__)
|
__full_version__ = __appname__ + '/' + str(__version__)
|
||||||
|
|
||||||
import os, platform, re, subprocess, sys
|
import os, platform, re, subprocess, sys, traceback
|
||||||
_distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
|
_distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
|
||||||
_release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
|
_release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
|
||||||
|
|
||||||
@ -137,9 +137,9 @@ def normalized_version(verstr, what=None):
|
|||||||
try:
|
try:
|
||||||
return verlib.NormalizedVersion(verlib.suggest_normalized_version(verstr))
|
return verlib.NormalizedVersion(verlib.suggest_normalized_version(verstr))
|
||||||
except (StandardError, verlib.IrrationalVersionError):
|
except (StandardError, verlib.IrrationalVersionError):
|
||||||
cls, value, traceback = sys.exc_info()
|
cls, value, trace = sys.exc_info()
|
||||||
raise PackagingError, ("could not parse %s due to %s: %s"
|
raise PackagingError, ("could not parse %s due to %s: %s"
|
||||||
% (what or repr(verstr), cls.__name__, value)), traceback
|
% (what or repr(verstr), cls.__name__, value)), trace
|
||||||
|
|
||||||
|
|
||||||
def get_package_versions_and_locations():
|
def get_package_versions_and_locations():
|
||||||
@ -187,7 +187,9 @@ def get_package_versions_and_locations():
|
|||||||
__import__(modulename)
|
__import__(modulename)
|
||||||
module = sys.modules[modulename]
|
module = sys.modules[modulename]
|
||||||
except ImportError:
|
except ImportError:
|
||||||
packages.append( (pkgname, (None, None, modulename)) )
|
etype, emsg, etrace = sys.exc_info()
|
||||||
|
trace_info = (emsg, ([None] + traceback.extract_tb(etrace))[-1])
|
||||||
|
packages.append( (pkgname, (None, None, trace_info)) )
|
||||||
else:
|
else:
|
||||||
if 'sqlite' in pkgname:
|
if 'sqlite' in pkgname:
|
||||||
packages.append( (pkgname, (get_version(module, 'version'), package_dir(module.__file__),
|
packages.append( (pkgname, (get_version(module, 'version'), package_dir(module.__file__),
|
||||||
@ -218,8 +220,8 @@ def check_requirement(req, vers_and_locs):
|
|||||||
return
|
return
|
||||||
(actual, location, comment) = vers_and_locs[name]
|
(actual, location, comment) = vers_and_locs[name]
|
||||||
if actual is None:
|
if actual is None:
|
||||||
# comment is the module name
|
# comment is (message, (filename, line number, function name, text)) for the original ImportError
|
||||||
raise ImportError("could not import %r for requirement %r" % (comment, req))
|
raise ImportError("for requirement %r: %s" % (req, comment))
|
||||||
if actual == 'unknown':
|
if actual == 'unknown':
|
||||||
return
|
return
|
||||||
actualver = normalized_version(actual, what="actual version %r of %s from %r" % (actual, name, location))
|
actualver = normalized_version(actual, what="actual version %r of %s from %r" % (actual, name, location))
|
||||||
|
Loading…
Reference in New Issue
Block a user