diff --git a/mercurial/extensions.py b/mercurial/extensions.py index fe108c4c78..22ef7d1d08 100644 --- a/mercurial/extensions.py +++ b/mercurial/extensions.py @@ -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') diff --git a/tests/test-bad-extension.t b/tests/test-bad-extension.t index f458086a20..d61add90ac 100644 --- a/tests/test-bad-extension.t +++ b/tests/test-bad-extension.t @@ -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 < 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)