extensions: add notloaded method to return extensions failed to load
authorJun Wu <quark@fb.com>
Wed, 10 Feb 2016 16:59:34 +0000
changeset 28155 7f430b2ac7fd
parent 28154 47f56b6bfed1
child 28156 75f586a1bf55
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.
mercurial/extensions.py
tests/test-bad-extension.t
--- a/mercurial/extensions.py	Mon Feb 15 14:57:06 2016 +0000
+++ b/mercurial/extensions.py	Wed Feb 10 16:59:34 2016 +0000
@@ -456,6 +456,10 @@
 
     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')
--- a/tests/test-bad-extension.t	Mon Feb 15 14:57:06 2016 +0000
+++ b/tests/test-bad-extension.t	Wed Feb 10 16:59:34 2016 +0000
@@ -31,6 +31,19 @@
   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)