[PATCH V2] extensions: add notloaded method to return extensions failed to load

Jun Wu quark at fb.com
Mon Feb 15 15:45:16 UTC 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1455123574 0
#      Wed Feb 10 16:59:34 2016 +0000
# Node ID f618a6ad59097fcb3e696e6e06fbf88915ba0e31
# Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
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.

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -456,6 +456,10 @@
 
     return exts
 
+def notloaded():
+    '''return short names of extensions that failed to load'''
+    return [name for name, mod in _extensions.items() 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
--- a/tests/test-bad-extension.t
+++ b/tests/test-bad-extension.t
@@ -38,3 +38,16 @@
   *** failed to import extension badext2: No module named badext2
   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


More information about the Mercurial-devel mailing list