Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/exthelper.py @ 46871:887f89b100ac
exthelper: improve docs to indicate what module vars are needed
I recently tried creating an extension "from scratch" using exthelper, and it
wasn't obvious that you needed these. I believe that a careful reading of one of
the comments would tell you that they were required, but it's easy to miss and
having the examples be "complete" is helpful.
Differential Revision: https://phab.mercurial-scm.org/D10295
author | Kyle Lippincott <spectral@google.com> |
---|---|
date | Tue, 30 Mar 2021 13:05:22 -0700 |
parents | bd22900e26ac |
children | 6000f5b25c9b |
comparison
equal
deleted
inserted
replaced
46870:41d43d12c2c4 | 46871:887f89b100ac |
---|---|
44 example:: | 44 example:: |
45 | 45 |
46 # ext.py | 46 # ext.py |
47 eh = exthelper.exthelper() | 47 eh = exthelper.exthelper() |
48 | 48 |
49 # As needed: | 49 # As needed (failure to do this will mean your registration will not |
50 # happen): | |
50 cmdtable = eh.cmdtable | 51 cmdtable = eh.cmdtable |
51 configtable = eh.configtable | 52 configtable = eh.configtable |
52 filesetpredicate = eh.filesetpredicate | 53 filesetpredicate = eh.filesetpredicate |
53 revsetpredicate = eh.revsetpredicate | 54 revsetpredicate = eh.revsetpredicate |
54 templatekeyword = eh.templatekeyword | 55 templatekeyword = eh.templatekeyword |
56 | |
57 # As needed (failure to do this will mean your eh.wrap*-decorated | |
58 # functions will not wrap, and/or your eh.*setup-decorated functions | |
59 # will not execute): | |
60 uisetup = eh.finaluisetup | |
61 extsetup = eh.finalextsetup | |
62 reposetup = eh.finalreposetup | |
63 uipopulate = eh.finaluipopulate | |
55 | 64 |
56 @eh.command(b'mynewcommand', | 65 @eh.command(b'mynewcommand', |
57 [(b'r', b'rev', [], _(b'operate on these revisions'))], | 66 [(b'r', b'rev', [], _(b'operate on these revisions'))], |
58 _(b'-r REV...'), | 67 _(b'-r REV...'), |
59 helpcategory=command.CATEGORY_XXX) | 68 helpcategory=command.CATEGORY_XXX) |
153 """ | 162 """ |
154 for c in self._uipopulatecallables: | 163 for c in self._uipopulatecallables: |
155 c(ui) | 164 c(ui) |
156 | 165 |
157 def finalextsetup(self, ui): | 166 def finalextsetup(self, ui): |
158 """Method to be used as a the extension extsetup | 167 """Method to be used as the extension extsetup |
159 | 168 |
160 The following operations belong here: | 169 The following operations belong here: |
161 | 170 |
162 - Changes depending on the status of other extensions. (if | 171 - Changes depending on the status of other extensions. (if |
163 extensions.find(b'mq')) | 172 extensions.find(b'mq')) |
199 def uisetup(self, call): | 208 def uisetup(self, call): |
200 """Decorated function will be executed during uisetup | 209 """Decorated function will be executed during uisetup |
201 | 210 |
202 example:: | 211 example:: |
203 | 212 |
213 # Required, otherwise your uisetup function(s) will not execute. | |
214 uisetup = eh.finaluisetup | |
215 | |
204 @eh.uisetup | 216 @eh.uisetup |
205 def setupbabar(ui): | 217 def setupbabar(ui): |
206 print('this is uisetup!') | 218 print('this is uisetup!') |
207 """ | 219 """ |
208 self._uicallables.append(call) | 220 self._uicallables.append(call) |
211 def uipopulate(self, call): | 223 def uipopulate(self, call): |
212 """Decorated function will be executed during uipopulate | 224 """Decorated function will be executed during uipopulate |
213 | 225 |
214 example:: | 226 example:: |
215 | 227 |
228 # Required, otherwise your uipopulate function(s) will not execute. | |
229 uipopulate = eh.finaluipopulate | |
230 | |
216 @eh.uipopulate | 231 @eh.uipopulate |
217 def setupfoo(ui): | 232 def setupfoo(ui): |
218 print('this is uipopulate!') | 233 print('this is uipopulate!') |
219 """ | 234 """ |
220 self._uipopulatecallables.append(call) | 235 self._uipopulatecallables.append(call) |
223 def extsetup(self, call): | 238 def extsetup(self, call): |
224 """Decorated function will be executed during extsetup | 239 """Decorated function will be executed during extsetup |
225 | 240 |
226 example:: | 241 example:: |
227 | 242 |
243 # Required, otherwise your extsetup function(s) will not execute. | |
244 extsetup = eh.finalextsetup | |
245 | |
228 @eh.extsetup | 246 @eh.extsetup |
229 def setupcelestine(ui): | 247 def setupcelestine(ui): |
230 print('this is extsetup!') | 248 print('this is extsetup!') |
231 """ | 249 """ |
232 self._extcallables.append(call) | 250 self._extcallables.append(call) |
234 | 252 |
235 def reposetup(self, call): | 253 def reposetup(self, call): |
236 """Decorated function will be executed during reposetup | 254 """Decorated function will be executed during reposetup |
237 | 255 |
238 example:: | 256 example:: |
257 | |
258 # Required, otherwise your reposetup function(s) will not execute. | |
259 reposetup = eh.finalreposetup | |
239 | 260 |
240 @eh.reposetup | 261 @eh.reposetup |
241 def setupzephir(ui, repo): | 262 def setupzephir(ui, repo): |
242 print('this is reposetup!') | 263 print('this is reposetup!') |
243 """ | 264 """ |
255 string that will be searched using `extension.find` if not found and | 276 string that will be searched using `extension.find` if not found and |
256 Abort error is raised. If the wrapping applies to an extension, it is | 277 Abort error is raised. If the wrapping applies to an extension, it is |
257 installed during `extsetup`. | 278 installed during `extsetup`. |
258 | 279 |
259 example:: | 280 example:: |
281 | |
282 # Required if `extension` is not provided | |
283 uisetup = eh.finaluisetup | |
284 # Required if `extension` is provided | |
285 extsetup = eh.finalextsetup | |
260 | 286 |
261 @eh.wrapcommand(b'summary') | 287 @eh.wrapcommand(b'summary') |
262 def wrapsummary(orig, ui, repo, *args, **kwargs): | 288 def wrapsummary(orig, ui, repo, *args, **kwargs): |
263 ui.note(b'Barry!') | 289 ui.note(b'Barry!') |
264 return orig(ui, repo, *args, **kwargs) | 290 return orig(ui, repo, *args, **kwargs) |
296 function to wrap. The wrapping is performed during `uisetup`. | 322 function to wrap. The wrapping is performed during `uisetup`. |
297 (there is no extension support) | 323 (there is no extension support) |
298 | 324 |
299 example:: | 325 example:: |
300 | 326 |
301 @eh.function(discovery, b'checkheads') | 327 # Required, otherwise the function will not be wrapped |
302 def wrapfunction(orig, *args, **kwargs): | 328 uisetup = eh.finaluisetup |
329 | |
330 @eh.wrapfunction(discovery, b'checkheads') | |
331 def wrapcheckheads(orig, *args, **kwargs): | |
303 ui.note(b'His head smashed in and his heart cut out') | 332 ui.note(b'His head smashed in and his heart cut out') |
304 return orig(*args, **kwargs) | 333 return orig(*args, **kwargs) |
305 """ | 334 """ |
306 | 335 |
307 def dec(wrapper): | 336 def dec(wrapper): |