##// END OF EJS Templates
extensions: fix load of module/__init__.py on OS X
Brendan Cully -
r4580:b1716a8b default
parent child Browse files
Show More
@@ -1,75 +1,76 b''
1 1 # extensions.py - extension handling for mercurial
2 2 #
3 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 import imp, os
9 9 import commands, hg, util, sys
10 10 from i18n import _
11 11
12 12 _extensions = {}
13 13
14 14 def find(name):
15 15 '''return module with given extension name'''
16 16 try:
17 17 return _extensions[name]
18 18 except KeyError:
19 19 for k, v in _extensions.iteritems():
20 20 if k.endswith('.' + name) or k.endswith('/' + name) or v == name:
21 21 return sys.modules[v]
22 22 raise KeyError(name)
23 23
24 24 def load(ui, name, path):
25 25 if name in _extensions:
26 26 return
27 27 if path:
28 28 # the module will be loaded in sys.modules
29 29 # choose an unique name so that it doesn't
30 30 # conflicts with other modules
31 31 module_name = "hgext_%s" % name.replace('.', '_')
32 32 if os.path.isdir(path):
33 33 # module/__init__.py style
34 fd, fpath, desc = imp.find_module('', [path])
34 d, f = os.path.split(path)
35 fd, fpath, desc = imp.find_module(f, [d])
35 36 mod = imp.load_module(module_name, fd, fpath, desc)
36 37 else:
37 38 mod = imp.load_source(module_name, path)
38 39 else:
39 40 def importh(name):
40 41 mod = __import__(name)
41 42 components = name.split('.')
42 43 for comp in components[1:]:
43 44 mod = getattr(mod, comp)
44 45 return mod
45 46 try:
46 47 mod = importh("hgext.%s" % name)
47 48 except ImportError:
48 49 mod = importh(name)
49 50 _extensions[name] = mod
50 51
51 52 uisetup = getattr(mod, 'uisetup', None)
52 53 if uisetup:
53 54 uisetup(ui)
54 55 reposetup = getattr(mod, 'reposetup', None)
55 56 if reposetup:
56 57 hg.repo_setup_hooks.append(reposetup)
57 58 cmdtable = getattr(mod, 'cmdtable', {})
58 59 overrides = [cmd for cmd in cmdtable if cmd in commands.table]
59 60 if overrides:
60 61 ui.warn(_("extension '%s' overrides commands: %s\n")
61 62 % (name, " ".join(overrides)))
62 63 commands.table.update(cmdtable)
63 64
64 65 def loadall(ui):
65 66 for name, path in ui.extensions():
66 67 try:
67 68 load(ui, name, path)
68 69 except (util.SignalInterrupt, KeyboardInterrupt):
69 70 raise
70 71 except Exception, inst:
71 72 ui.warn(_("*** failed to import extension %s: %s\n") %
72 73 (name, inst))
73 74 if ui.print_exc():
74 75 return 1
75 76
General Comments 0
You need to be logged in to leave comments. Login now