Mercurial > public > mercurial-scm > hg
comparison mercurial/extensions.py @ 32342:e5fbf9687600
extensions: prohibit registration of command without using @command (API)
Detect the problem earlier for better error indication. I'm tired of teaching
users that the mq extension is not guilty but the third-party extension is.
https://bitbucket.org/tortoisehg/thg/issues?q=%27norepo%27
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 13 May 2017 15:41:50 +0900 |
parents | b88d879e468a |
children | d47d7d3bd07b |
comparison
equal
deleted
inserted
replaced
32341:b88d879e468a | 32342:e5fbf9687600 |
---|---|
116 ui.debug('could not import %s (%s): trying %s\n' | 116 ui.debug('could not import %s (%s): trying %s\n' |
117 % (failed, _forbytes(err), next)) | 117 % (failed, _forbytes(err), next)) |
118 if ui.debugflag: | 118 if ui.debugflag: |
119 ui.traceback() | 119 ui.traceback() |
120 | 120 |
121 # attributes set by registrar.command | |
122 _cmdfuncattrs = ('norepo', 'optionalrepo', 'inferrepo') | |
123 | |
124 def _validatecmdtable(cmdtable): | |
125 """Check if extension commands have required attributes""" | |
126 for c, e in cmdtable.iteritems(): | |
127 f = e[0] | |
128 missing = [a for a in _cmdfuncattrs if not util.safehasattr(f, a)] | |
129 if not missing: | |
130 continue | |
131 raise error.ProgrammingError( | |
132 'missing attributes: %s' % ', '.join(missing), | |
133 hint="use @command decorator to register '%s'" % c) | |
134 | |
121 def load(ui, name, path): | 135 def load(ui, name, path): |
122 if name.startswith('hgext.') or name.startswith('hgext/'): | 136 if name.startswith('hgext.') or name.startswith('hgext/'): |
123 shortname = name[6:] | 137 shortname = name[6:] |
124 else: | 138 else: |
125 shortname = name | 139 shortname = name |
137 minver = getattr(mod, 'minimumhgversion', None) | 151 minver = getattr(mod, 'minimumhgversion', None) |
138 if minver and util.versiontuple(minver, 2) > util.versiontuple(n=2): | 152 if minver and util.versiontuple(minver, 2) > util.versiontuple(n=2): |
139 ui.warn(_('(third party extension %s requires version %s or newer ' | 153 ui.warn(_('(third party extension %s requires version %s or newer ' |
140 'of Mercurial; disabling)\n') % (shortname, minver)) | 154 'of Mercurial; disabling)\n') % (shortname, minver)) |
141 return | 155 return |
156 _validatecmdtable(getattr(mod, 'cmdtable', {})) | |
142 | 157 |
143 _extensions[shortname] = mod | 158 _extensions[shortname] = mod |
144 _order.append(shortname) | 159 _order.append(shortname) |
145 for fn in _aftercallbacks.get(shortname, []): | 160 for fn in _aftercallbacks.get(shortname, []): |
146 fn(loaded=True) | 161 fn(loaded=True) |