[PATCH 1 of 3] registrar: add templatekeyword to mark a function as template keyword (API)
Yuya Nishihara
yuya at tcha.org
Sun Mar 13 11:40:23 EDT 2016
On Sun, 13 Mar 2016 22:57:56 +0900, FUJIWARA Katsunori wrote:
> # code for portability >>>>
> try:
> from mercurial import registrar
> if not util.safehasattr(registrar, 'templatekeyword'):
> raise ImportError()
>
> templatekeyword = registrar.templatekeyword()
> loadkeyword = lambda registrarobj: None # nop
> except ImportError:
> # registrar.templatekeyword isn't available = loading by old hg
>
> # minimum copy from registrar._funcregistrarbase
> class _funcregistrarbase(object):
> ....
>
> templatekeyword = _funcregistrarbase()
> templatekeyword._docformat = ":%s: %s"
>
> # minimum copy from templatekw.loadkeyword
> def loadkeyword(registrarobj):
> from mercurial import templatekw
> for name, func in registrarobj._table.iteritems():
> templatekw.keywords[name] = func
> # <<<< code for portability
or simply use noop decorator:
_registrarloaded = False
try:
from mercurial import registrar
templatekeyword = registrar.templatekeyword()
_registrarloaded = True
except (ImportError, AttributeError):
def templatekeyword(decl):
return lambda func: func
def extsetup(ui):
if not _registrarloaded:
templatekw.keywords['foo'] = kwfoo
More information about the Mercurial-devel
mailing list