Mercurial > hg-stable
changeset 20430:d98ba4a87427
merge with stable
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 10 Feb 2014 17:31:26 -0600 |
parents | f5b560c60bcd (current diff) aac87f70f38e (diff) |
children | bebf8b8479f3 |
files | |
diffstat | 2 files changed, 26 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/demandimport.py Thu Feb 06 14:29:37 2014 -0800 +++ b/mercurial/demandimport.py Mon Feb 10 17:31:26 2014 -0600 @@ -162,6 +162,9 @@ 'mimetools', ] +def isenabled(): + return __builtin__.__import__ == _demandimport + def enable(): "enable global demand-loading of modules" __builtin__.__import__ = _demandimport
--- a/mercurial/hook.py Thu Feb 06 14:29:37 2014 -0800 +++ b/mercurial/hook.py Mon Feb 10 17:31:26 2014 -0600 @@ -36,28 +36,33 @@ if modpath and modfile: sys.path = sys.path[:] + [modpath] modname = modfile - try: + demandimportenabled = demandimport.isenabled() + if demandimportenabled: demandimport.disable() - obj = __import__(modname) - demandimport.enable() - except ImportError: - e1 = sys.exc_type, sys.exc_value, sys.exc_traceback + try: try: - # extensions are loaded with hgext_ prefix - obj = __import__("hgext_%s" % modname) - demandimport.enable() + obj = __import__(modname) except ImportError: + e1 = sys.exc_type, sys.exc_value, sys.exc_traceback + try: + # extensions are loaded with hgext_ prefix + obj = __import__("hgext_%s" % modname) + except ImportError: + e2 = sys.exc_type, sys.exc_value, sys.exc_traceback + if ui.tracebackflag: + ui.warn(_('exception from first failed import ' + 'attempt:\n')) + ui.traceback(e1) + if ui.tracebackflag: + ui.warn(_('exception from second failed import ' + 'attempt:\n')) + ui.traceback(e2) + raise util.Abort(_('%s hook is invalid ' + '(import of "%s" failed)') % + (hname, modname)) + finally: + if demandimportenabled: demandimport.enable() - e2 = sys.exc_type, sys.exc_value, sys.exc_traceback - if ui.tracebackflag: - ui.warn(_('exception from first failed import attempt:\n')) - ui.traceback(e1) - if ui.tracebackflag: - ui.warn(_('exception from second failed import attempt:\n')) - ui.traceback(e2) - raise util.Abort(_('%s hook is invalid ' - '(import of "%s" failed)') % - (hname, modname)) sys.path = oldpaths try: for p in funcname.split('.')[1:]: