[PATCH] extensions: raise when trying to find an extension that failed to load

Idan Kamara idankk86 at gmail.com
Mon May 23 15:21:47 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1306181340 -10800
# Node ID cc8b69b0d997ba8ef8e667142f890fef58c28ec6
# Parent  054da1e0afbe1728a395830cfc769a2a01a7a3ef
extensions: raise when trying to find an extension that failed to load

extensions that depend on other extensions (such as record) use this pattern
to check if the dependant extension is available:

    try:
        mq = extensions.find('mq')
    except KeyError:
        return

but since if an error occurs while loading an extension it leaves its entry
in the _extensions map as None, we want to raise in that situation too.

(rather than adding another check if the return value is None)

diff -r 054da1e0afbe -r cc8b69b0d997 mercurial/extensions.py
--- a/mercurial/extensions.py	Sun May 22 16:10:03 2011 +0300
+++ b/mercurial/extensions.py	Mon May 23 23:09:00 2011 +0300
@@ -21,13 +21,17 @@
 
 def find(name):
     '''return module with given extension name'''
+    mod = None
     try:
-        return _extensions[name]
+        mod =  _extensions[name]
     except KeyError:
         for k, v in _extensions.iteritems():
             if k.endswith('.' + name) or k.endswith('/' + name):
-                return v
+                mod = v
+                break
+    if not mod:
         raise KeyError(name)
+    return mod
 
 def loadpath(path, module_name):
     module_name = module_name.replace('.', '_')
diff -r 054da1e0afbe -r cc8b69b0d997 tests/test-qrecord.t
--- a/tests/test-qrecord.t	Sun May 22 16:10:03 2011 +0300
+++ b/tests/test-qrecord.t	Mon May 23 23:09:00 2011 +0300
@@ -99,9 +99,24 @@
   abort: 'mq' extension not loaded
   [255]
 
+help (bad mq)
+
+  $ echo "mq=nonexistant" >> $HGRCPATH
+  $ hg help qrecord
+  *** failed to import extension mq from nonexistant: [Errno 2] No such file or directory
+  hg qrecord [OPTION]... PATCH [FILE]...
+  
+  interactively record a new patch
+  
+      See "hg help qnew" & "hg help record" for more information and usage.
+  
+  use "hg -v help qrecord" to show global options
+
 help (mq present)
 
-  $ echo "mq="              >> $HGRCPATH
+  $ sed 's/mq=nonexistant/mq=/' $HGRCPATH > hgrc.tmp
+  $ mv hgrc.tmp $HGRCPATH
+
   $ hg help qrecord
   hg qrecord [OPTION]... PATCH [FILE]...
   


More information about the Mercurial-devel mailing list