Patchwork [1,of,1] extensions: include hgext.experiments package when loading extensions

login
register
mail settings
Submitter Martijn Pieters
Date Jan. 14, 2016, 9:50 p.m.
Message ID <421d0643adc332cc9347.1452808217@mjpieters-mbp>
Download mbox | patch
Permalink /patch/12774/
State Deferred
Headers show

Comments

Martijn Pieters - Jan. 14, 2016, 9:50 p.m.
# HG changeset patch
# User Martijn Pieters <mj@zopatista.com>
# Date 1452806919 0
#      Thu Jan 14 21:28:39 2016 +0000
# Node ID 421d0643adc332cc9347da8cfb15cbb9c9ce6590
# Parent  443848eece189002c542339dc1cf84f49a94c824
extensions: include hgext.experiments package when loading extensions

Search for extensions not only in hgext.* but in hgext.extensions as well. This
opens up the way to including experimental extensions that don't have to follow
the stricter mercurial core release schedule and requirements.

Patch

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -26,6 +26,7 @@ 
 _order = []
 _builtin = set(['hbisect', 'bookmarks', 'parentrevspec', 'progress', 'interhg',
                 'inotify'])
+_extpath = ['hgext', 'hgext.experimental']
 
 def extensions(ui=None):
     if ui:
@@ -72,8 +73,10 @@ 
             raise
 
 def load(ui, name, path):
-    if name.startswith('hgext.') or name.startswith('hgext/'):
-        shortname = name[6:]
+    for prefix in _extpath:
+        if name.startswith(prefix + '.') or name.startswith(prefix + '/'):
+            shortname = name[len(prefix) + 1:]
+            break
     else:
         shortname = name
     if shortname in _builtin:
@@ -93,13 +96,19 @@ 
             for comp in components[1:]:
                 mod = getattr(mod, comp)
             return mod
-        try:
-            mod = importh("hgext.%s" % name)
-        except ImportError as err:
-            ui.debug('could not import hgext.%s (%s): trying %s\n'
-                     % (name, err, name))
-            if ui.debugflag:
-                ui.traceback()
+        for prefix in _extpath:
+            try:
+                mod = importh("%s.%s" % (prefix, name))
+            except ImportError as err:
+                ui.debug('could not import %s.%s (%s)\n' %
+                         (prefix, name, err))
+                if ui.debugflag:
+                    ui.traceback()
+            else:
+                break
+        else:
+            ui.debug('could not import prefixed %s: trying plain %s\n' %
+                     (name, name))
             mod = importh(name)
 
     # Before we do anything with the extension, check against minimum stated
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
@@ -32,9 +32,13 @@ 
   *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
   Traceback (most recent call last):
   Exception: bit bucket overflow
-  could not import hgext.badext2 (No module named *badext2): trying badext2 (glob)
+  could not import hgext.badext2 (No module named *badext2) (glob)
   Traceback (most recent call last):
   ImportError: No module named *badext2 (glob)
+  could not import hgext.experimental.badext2 (No module named *badext2) (glob)
+  Traceback (most recent call last):
+  ImportError: No module named experimental.badext2
+  could not import prefixed badext2: trying plain badext2
   *** failed to import extension badext2: No module named badext2
   Traceback (most recent call last):
   ImportError: No module named badext2