[PATCH 2 of 3] extensions: factor import error reporting out

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Mar 11 06:47:04 EST 2016


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1457692138 0
#      Fri Mar 11 10:28:58 2016 +0000
# Node ID 22f8428e07e42b110ee72cfe2725f714617686b5
# Parent  9979de04196de6f0a7609d49ba447f88228a2507
# EXP-Topic hgext3rd
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r 22f8428e07e4
extensions: factor import error reporting out

To clarify third party extensions lookup, we are about to add a third place
where extensions are searched for. So we factor the error reporting logic out to
be able to easily reuse it in the next patch.

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -77,10 +77,16 @@ def _importh(name):
     components = name.split('.')
     for comp in components[1:]:
         mod = getattr(mod, comp)
     return mod
 
+def _reportimporterror(ui, err, failed, next):
+    ui.debug('could not import %s (%s): trying %s\n'
+             % (failed, err, next))
+    if ui.debugflag:
+        ui.traceback()
+
 def load(ui, name, path):
     if name.startswith('hgext.') or name.startswith('hgext/'):
         shortname = name[6:]
     else:
         shortname = name
@@ -96,14 +102,11 @@ def load(ui, name, path):
         mod = loadpath(path, 'hgext.%s' % name)
     else:
         try:
             mod = _importh("hgext.%s" % name)
         except ImportError as err:
-            ui.debug('could not import hgext.%s (%s): trying %s\n'
-                     % (name, err, name))
-            if ui.debugflag:
-                ui.traceback()
+            _reportimporterror(ui, err, "hgext.%s" % name, name)
             mod = _importh(name)
 
     # Before we do anything with the extension, check against minimum stated
     # compatibility. This gives extension authors a mechanism to have their
     # extensions short circuit when loaded with a known incompatible version


More information about the Mercurial-devel mailing list