# HG changeset patch # User Brendan Cully # Date 1181767600 25200 # Node ID 622d8ed78b4731389a8b78fa0900e4d7567db26c # Parent 8044be585b91a9bfe70a1891e246aef918d285d9 extensions: load modules in module/__init__.py form. For example, convert=/path/to/convert now works. diff --git a/mercurial/extensions.py b/mercurial/extensions.py --- a/mercurial/extensions.py +++ b/mercurial/extensions.py @@ -5,7 +5,8 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import imp, commands, hg, util, sys +import imp, os +import commands, hg, util, sys from i18n import _ _extensions = {} @@ -28,7 +29,12 @@ def load(ui, name, path): # choose an unique name so that it doesn't # conflicts with other modules module_name = "hgext_%s" % name.replace('.', '_') - mod = imp.load_source(module_name, path) + if os.path.isdir(path): + # module/__init__.py style + fd, fpath, desc = imp.find_module('', [path]) + mod = imp.load_module(module_name, fd, fpath, desc) + else: + mod = imp.load_source(module_name, path) else: def importh(name): mod = __import__(name) diff --git a/tests/test-extension b/tests/test-extension --- a/tests/test-extension +++ b/tests/test-extension @@ -29,6 +29,10 @@ commands.norepo += ' bar' EOF abspath=`pwd`/foobar.py +mkdir barfoo +cp foobar.py barfoo/__init__.py +barfoopath=`pwd`/barfoo + hg init a cd a echo foo > file @@ -43,3 +47,9 @@ cd .. hg clone a b hg bar + +echo '% module/__init__.py-style' +echo '[extensions]' > $HGRCPATH +echo "barfoo = $barfoopath" >> $HGRCPATH +cd a +hg foo diff --git a/tests/test-extension.out b/tests/test-extension.out --- a/tests/test-extension.out +++ b/tests/test-extension.out @@ -13,3 +13,9 @@ 1 files updated, 0 files merged, 0 files uisetup called ui.parentui is None Bar +% module/__init__.py-style +uisetup called +ui.parentui is None +reposetup called for a +ui == repo.ui +Foo