refactor: extract templates into a new file
authorBoris Feld <boris.feld@octobus.net>
Fri, 26 May 2017 16:00:05 +0200
changeset 2485 e6ecd35e99ec
parent 2484 262d684851dc
child 2486 cd4290f923b7
refactor: extract templates into a new file Extract evolve template from evolve/__init__.py to evolve/templatekw.py as more templates will come in the future.
hgext3rd/evolve/__init__.py
hgext3rd/evolve/templatekw.py
--- a/hgext3rd/evolve/__init__.py	Tue May 23 19:48:04 2017 +0200
+++ b/hgext3rd/evolve/__init__.py	Fri May 26 16:00:05 2017 +0200
@@ -164,7 +164,6 @@
     phases,
     revset,
     scmutil,
-    templatekw,
     obsolete
 )
 
@@ -181,7 +180,8 @@
     obsexchange,
     safeguard,
     utility,
-    obshistory
+    obshistory,
+    templatekw
 )
 
 __version__ = metadata.__version__
@@ -224,6 +224,7 @@
 eh.merge(safeguard.eh)
 eh.merge(obscache.eh)
 eh.merge(obshistory.eh)
+eh.merge(templatekw.eh)
 uisetup = eh.final_uisetup
 extsetup = eh.final_extsetup
 reposetup = eh.final_reposetup
@@ -515,29 +516,6 @@
     s.sort()
     return subset & s
 
-### template keywords
-# XXX it does not handle troubles well :-/
-
-@eh.templatekw('obsolete')
-def obsoletekw(repo, ctx, templ, **args):
-    """:obsolete: String. Whether the changeset is ``obsolete``.
-    """
-    if ctx.obsolete():
-        return 'obsolete'
-    return ''
-
-@eh.templatekw('troubles')
-def showtroubles(**args):
-    """:troubles: List of strings. Evolution troubles affecting the changeset
-    (zero or more of "unstable", "divergent" or "bumped")."""
-    ctx = args['ctx']
-    try:
-        # specify plural= explicitly to trigger TypeError on hg < 4.2
-        return templatekw.showlist('trouble', ctx.troubles(), args,
-                                   plural='troubles')
-    except TypeError:
-        return templatekw.showlist('trouble', ctx.troubles(), plural='troubles',
-                                   **args)
 
 #####################################################################
 ### Various trouble warning                                       ###
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hgext3rd/evolve/templatekw.py	Fri May 26 16:00:05 2017 +0200
@@ -0,0 +1,43 @@
+# Copyright 2011 Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
+#                Logilab SA        <contact@logilab.fr>
+#                Pierre-Yves David <pierre-yves.david@ens-lyon.org>
+#                Patrick Mezard <patrick@mezard.eu>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+"""evolve templates
+"""
+
+from . import (
+    exthelper,
+)
+
+from mercurial import (
+    templatekw,
+)
+
+eh = exthelper.exthelper()
+
+### template keywords
+# XXX it does not handle troubles well :-/
+
+@eh.templatekw('obsolete')
+def obsoletekw(repo, ctx, templ, **args):
+    """:obsolete: String. Whether the changeset is ``obsolete``.
+    """
+    if ctx.obsolete():
+        return 'obsolete'
+    return ''
+
+@eh.templatekw('troubles')
+def showtroubles(**args):
+    """:troubles: List of strings. Evolution troubles affecting the changeset
+    (zero or more of "unstable", "divergent" or "bumped")."""
+    ctx = args['ctx']
+    try:
+        # specify plural= explicitly to trigger TypeError on hg < 4.2
+        return templatekw.showlist('trouble', ctx.troubles(), args,
+                                   plural='troubles')
+    except TypeError:
+        return templatekw.showlist('trouble', ctx.troubles(), plural='troubles',
+                                   **args)