comparison mercurial/registrar.py @ 38428:aa98392eb5b0

templatefuncs: declare resource requirements for future use
author Yuya Nishihara <yuya@tcha.org>
date Thu, 14 Jun 2018 21:18:58 +0900
parents dfc51a482031
children 5d9749c598f0
comparison
equal deleted inserted replaced
38427:4b73f316ba0e 38428:aa98392eb5b0
349 349
350 Usage:: 350 Usage::
351 351
352 templatefunc = registrar.templatefunc() 352 templatefunc = registrar.templatefunc()
353 353
354 @templatefunc('myfunc(arg1, arg2[, arg3])', argspec='arg1 arg2 arg3') 354 @templatefunc('myfunc(arg1, arg2[, arg3])', argspec='arg1 arg2 arg3',
355 requires={'ctx'})
355 def myfuncfunc(context, mapping, args): 356 def myfuncfunc(context, mapping, args):
356 '''Explanation of this template function .... 357 '''Explanation of this template function ....
357 ''' 358 '''
358 pass 359 pass
359 360
361 362
362 If optional 'argspec' is defined, the function will receive 'args' as 363 If optional 'argspec' is defined, the function will receive 'args' as
363 a dict of named arguments. Otherwise 'args' is a list of positional 364 a dict of named arguments. Otherwise 'args' is a list of positional
364 arguments. 365 arguments.
365 366
367 Optional argument 'requires' should be a collection of resource names
368 which the template function depends on.
369
366 'templatefunc' instance in example above can be used to 370 'templatefunc' instance in example above can be used to
367 decorate multiple functions. 371 decorate multiple functions.
368 372
369 Decorated functions are registered automatically at loading 373 Decorated functions are registered automatically at loading
370 extension, if an instance named as 'templatefunc' is used for 374 extension, if an instance named as 'templatefunc' is used for
372 376
373 Otherwise, explicit 'templatefuncs.loadfunction()' is needed. 377 Otherwise, explicit 'templatefuncs.loadfunction()' is needed.
374 """ 378 """
375 _getname = _funcregistrarbase._parsefuncdecl 379 _getname = _funcregistrarbase._parsefuncdecl
376 380
377 def _extrasetup(self, name, func, argspec=None): 381 def _extrasetup(self, name, func, argspec=None, requires=()):
378 func._argspec = argspec 382 func._argspec = argspec
383 func._requires = requires
379 384
380 class internalmerge(_funcregistrarbase): 385 class internalmerge(_funcregistrarbase):
381 """Decorator to register in-process merge tool 386 """Decorator to register in-process merge tool
382 387
383 Usage:: 388 Usage::