Mercurial > public > mercurial-scm > hg
comparison mercurial/extensions.py @ 5192:60acf1432ee0
Move cmdtable and reposetup handling out of extensions.py
A new function (extensions.extensions) allows the code that is
interested in those attributes to handle them directly.
This allows some cleanups of extensions.py. Notably, we can
remove the extensions.commandtable hack.
It also makes it easier to add standard extension attributes,
like a "hgwebsetup" function or a "helptable" dict that augments
the data in help.py, etc.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Fri, 17 Aug 2007 17:33:27 -0300 |
parents | 4f648e95caca |
children | b12432b1c2c7 |
comparison
equal
deleted
inserted
replaced
5191:831ebc408ffb | 5192:60acf1432ee0 |
---|---|
8 import imp, os | 8 import imp, os |
9 import util, sys | 9 import util, sys |
10 from i18n import _ | 10 from i18n import _ |
11 | 11 |
12 _extensions = {} | 12 _extensions = {} |
13 commandtable = {} | 13 _order = [] |
14 setuphooks = [] | 14 |
15 def extensions(): | |
16 for name in _order: | |
17 module = _extensions[name] | |
18 if module: | |
19 yield name, module | |
15 | 20 |
16 def find(name): | 21 def find(name): |
17 '''return module with given extension name''' | 22 '''return module with given extension name''' |
18 try: | 23 try: |
19 return _extensions[name] | 24 return _extensions[name] |
53 try: | 58 try: |
54 mod = importh("hgext.%s" % name) | 59 mod = importh("hgext.%s" % name) |
55 except ImportError: | 60 except ImportError: |
56 mod = importh(name) | 61 mod = importh(name) |
57 _extensions[shortname] = mod | 62 _extensions[shortname] = mod |
63 _order.append(shortname) | |
58 | 64 |
59 uisetup = getattr(mod, 'uisetup', None) | 65 uisetup = getattr(mod, 'uisetup', None) |
60 if uisetup: | 66 if uisetup: |
61 uisetup(ui) | 67 uisetup(ui) |
62 reposetup = getattr(mod, 'reposetup', None) | |
63 if reposetup: | |
64 setuphooks.append(reposetup) | |
65 cmdtable = getattr(mod, 'cmdtable', {}) | |
66 overrides = [cmd for cmd in cmdtable if cmd in commandtable] | |
67 if overrides: | |
68 ui.warn(_("extension '%s' overrides commands: %s\n") | |
69 % (name, " ".join(overrides))) | |
70 commandtable.update(cmdtable) | |
71 | 68 |
72 def loadall(ui): | 69 def loadall(ui): |
73 result = ui.configitems("extensions") | 70 result = ui.configitems("extensions") |
74 for i, (name, path) in enumerate(result): | 71 for i, (name, path) in enumerate(result): |
75 if path: | 72 if path: |