From patchwork Fri Mar 11 11:47:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,3] extensions: factor import error reporting out From: Pierre-Yves David X-Patchwork-Id: 13758 Message-Id: <22f8428e07e42b110ee7.1457696824@marginatus.alto.octopoid.net> To: mercurial-devel@mercurial-scm.org Cc: raf@durin42.com Date: Fri, 11 Mar 2016 11:47:04 +0000 # HG changeset patch # User Pierre-Yves David # 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