Mercurial > hg-stable
changeset 28505:d5512a0a8ad6
extensions: extract the 'importh' closure as normal function
There is no reason for this to be a closure so we extract it for clarity.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Fri, 11 Mar 2016 10:24:54 +0000 |
parents | 3c90090320ad |
children | 10252652c6e4 |
files | mercurial/extensions.py |
diffstat | 1 files changed, 10 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/extensions.py Fri Mar 11 15:40:58 2016 -0800 +++ b/mercurial/extensions.py Fri Mar 11 10:24:54 2016 +0000 @@ -71,6 +71,14 @@ exc.filename = path # python does not fill this raise +def _importh(name): + """import and return the <name> module""" + mod = __import__(name) + components = name.split('.') + for comp in components[1:]: + mod = getattr(mod, comp) + return mod + def load(ui, name, path): if name.startswith('hgext.') or name.startswith('hgext/'): shortname = name[6:] @@ -87,20 +95,14 @@ # conflicts with other modules mod = loadpath(path, 'hgext.%s' % name) else: - def importh(name): - mod = __import__(name) - components = name.split('.') - for comp in components[1:]: - mod = getattr(mod, comp) - return mod try: - mod = importh("hgext.%s" % name) + 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() - mod = importh(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