Commit 6e937e55 authored by Julien Muchembled's avatar Julien Muchembled

jinja2: by default, rerender on update only if the template may have changed

parent 36d4fba9
...@@ -485,6 +485,53 @@ path):: ...@@ -485,6 +485,53 @@ path)::
b1foo b1foo
bc1foo bc1foo
``update`` - force rerendering on update
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
By default, and like the default recipe, nothing is done on update if the
template is known in advance to be the same, either because it's inline or
a md5sum is given::
>>> write('buildout.cfg',
... '''
... [buildout]
... parts = template
...
... [template]
... recipe = slapos.recipe.template:jinja2
... inline = {{ os.environ['FOO'] }}
... output = foo
... context = import os os
... ''')
>>> os.environ['FOO'] = '1'
>>> run_buildout()
Uninstalling template.
Installing template.
>>> cat('foo')
1
>>> os.environ['FOO'] = '2'
>>> run_buildout()
Updating template.
>>> cat('foo')
1
But Jinja2 is such that the output may depend on other things than buildout
data and it may be wanted to force update in such case::
>>> with open('buildout.cfg', 'a') as f:
... f.writelines(['update = true'])
>>> run_buildout()
Uninstalling template.
Installing template.
>>> cat('foo')
2
>>> os.environ['FOO'] = '1'
>>> run_buildout()
Updating template.
>>> cat('foo')
1
>>> del os.environ['FOO']
``encoding`` ``encoding``
~~~~~~~~~~~~ ~~~~~~~~~~~~
......
...@@ -61,6 +61,9 @@ def get_umask(): ...@@ -61,6 +61,9 @@ def get_umask():
get_umask = lambda: umask get_umask = lambda: umask
return umask return umask
def is_true(value, default=False):
return default if value is None else ('false', 'true').index(value)
class Recipe(object): class Recipe(object):
......
...@@ -30,7 +30,7 @@ import zc.buildout ...@@ -30,7 +30,7 @@ import zc.buildout
from jinja2 import Environment, StrictUndefined, \ from jinja2 import Environment, StrictUndefined, \
BaseLoader, TemplateNotFound, PrefixLoader BaseLoader, TemplateNotFound, PrefixLoader
import six import six
from . import Recipe from . import is_true, Recipe
DEFAULT_CONTEXT = {x.__name__: x for x in ( DEFAULT_CONTEXT = {x.__name__: x for x in (
abs, all, any, bin, bool, bytes, callable, chr, complex, dict, divmod, abs, all, any, bin, bool, bytes, callable, chr, complex, dict, divmod,
...@@ -145,6 +145,7 @@ class Recipe(Recipe): ...@@ -145,6 +145,7 @@ class Recipe(Recipe):
args = self.buildout, name, options args = self.buildout, name, options
self.once = options.get('once') self.once = options.get('once')
self.encoding = options.get('encoding', 'utf-8') self.encoding = options.get('encoding', 'utf-8')
self._update = is_true(options.get('update'))
import_delimiter = options.get('import-delimiter', import_delimiter = options.get('import-delimiter',
DEFAULT_IMPORT_DELIMITER) DEFAULT_IMPORT_DELIMITER)
import_dict = {} import_dict = {}
...@@ -223,4 +224,8 @@ class Recipe(Recipe): ...@@ -223,4 +224,8 @@ class Recipe(Recipe):
return return
return installed return installed
update = install def update(self):
if self._update:
self.install()
else:
super(Recipe, self).update()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment