extensions: add notloaded method to return extensions failed to load

Before this patch, there is no easy way to detect if there are extensions
failed to load. While this is okay for most situations, chgserver is designed
to preload all extensions specified in config and does need the information.
This patch adds extensions.notloaded() to return names of extensions failed
to load.
This commit is contained in:
Jun Wu 2016-02-10 16:59:34 +00:00
parent f0666adeb0
commit 6ee6b437f3
2 changed files with 17 additions and 0 deletions

View File

@ -456,6 +456,10 @@ def enabled(shortname=True):
return exts
def notloaded():
'''return short names of extensions that failed to load'''
return [name for name, mod in _extensions.iteritems() if mod is None]
def moduleversion(module):
'''return version information from given module as a string'''
if (util.safehasattr(module, 'getversion')

View File

@ -31,6 +31,19 @@ show traceback
Traceback (most recent call last):
ImportError: No module named badext2
names of extensions failed to load can be accessed via extensions.notloaded()
$ cat <<EOF > showbadexts.py
> from mercurial import cmdutil, commands, extensions
> cmdtable = {}
> command = cmdutil.command(cmdtable)
> @command('showbadexts', norepo=True)
> def showbadexts(ui, *pats, **opts):
> ui.write('BADEXTS: %s' % ' '.join(sorted(extensions.notloaded())))
> EOF
$ hg --config extensions.badexts=showbadexts.py showbadexts 2>&1 | grep '^BADEXTS'
BADEXTS: badext badext2
show traceback for ImportError of hgext.name if debug is set
(note that --debug option isn't applied yet when loading extensions)