Mercurial > hg-stable
changeset 18111:d7c28954d901
hook: disable demandimport before importing hooks
This solved an obscure bug for me. In upgrading Distribute on the server, a
patch was added to has a try: import a except ImportError thing that's only
supposed to work with Python 3.3. I'm using 2.7. My hook failed with an
ImportError because of this. It seems kind of sensible to turn off
demandimport before importing the hook, since the except ImportError pattern
is used quite a bit in Python code (including in other Distribute code).
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Thu, 20 Dec 2012 21:26:30 +0100 |
parents | acfc6fab1361 |
children | 569091b938a9 |
files | mercurial/hook.py |
diffstat | 1 files changed, 5 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hook.py Thu Dec 20 15:18:41 2012 +0100 +++ b/mercurial/hook.py Thu Dec 20 21:26:30 2012 +0100 @@ -7,7 +7,7 @@ from i18n import _ import os, sys -import extensions, util +import extensions, util, demandimport def _pythonhook(ui, repo, name, hname, funcname, args, throw): '''call python hook. hook is callable object, looked up as @@ -35,13 +35,17 @@ sys.path = sys.path[:] + [modpath] modname = modfile try: + demandimport.disable() obj = __import__(modname) + demandimport.enable() except ImportError: e1 = sys.exc_type, sys.exc_value, sys.exc_traceback try: # extensions are loaded with hgext_ prefix obj = __import__("hgext_%s" % modname) + demandimport.enable() except ImportError: + demandimport.enable() e2 = sys.exc_type, sys.exc_value, sys.exc_traceback if ui.tracebackflag: ui.warn(_('exception from first failed import attempt:\n'))