Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/extensions.py @ 4569:622d8ed78b47
extensions: load modules in module/__init__.py form.
For example, convert=/path/to/convert now works.
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Wed, 13 Jun 2007 13:46:40 -0700 |
parents | 9338be783398 |
children | b1716a8b32d3 |
comparison
equal
deleted
inserted
replaced
4563:8044be585b91 | 4569:622d8ed78b47 |
---|---|
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> | 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
4 # | 4 # |
5 # This software may be used and distributed according to the terms | 5 # This software may be used and distributed according to the terms |
6 # of the GNU General Public License, incorporated herein by reference. | 6 # of the GNU General Public License, incorporated herein by reference. |
7 | 7 |
8 import imp, commands, hg, util, sys | 8 import imp, os |
9 import commands, hg, util, sys | |
9 from i18n import _ | 10 from i18n import _ |
10 | 11 |
11 _extensions = {} | 12 _extensions = {} |
12 | 13 |
13 def find(name): | 14 def find(name): |
26 if path: | 27 if path: |
27 # the module will be loaded in sys.modules | 28 # the module will be loaded in sys.modules |
28 # choose an unique name so that it doesn't | 29 # choose an unique name so that it doesn't |
29 # conflicts with other modules | 30 # conflicts with other modules |
30 module_name = "hgext_%s" % name.replace('.', '_') | 31 module_name = "hgext_%s" % name.replace('.', '_') |
31 mod = imp.load_source(module_name, path) | 32 if os.path.isdir(path): |
33 # module/__init__.py style | |
34 fd, fpath, desc = imp.find_module('', [path]) | |
35 mod = imp.load_module(module_name, fd, fpath, desc) | |
36 else: | |
37 mod = imp.load_source(module_name, path) | |
32 else: | 38 else: |
33 def importh(name): | 39 def importh(name): |
34 mod = __import__(name) | 40 mod = __import__(name) |
35 components = name.split('.') | 41 components = name.split('.') |
36 for comp in components[1:]: | 42 for comp in components[1:]: |