Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.recipe.template
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
slapos.recipe.template
Commits
6e937e55
Commit
6e937e55
authored
Feb 01, 2022
by
Julien Muchembled
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jinja2: by default, rerender on update only if the template may have changed
parent
36d4fba9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
2 deletions
+57
-2
slapos/recipe/template/README.jinja2.txt
slapos/recipe/template/README.jinja2.txt
+47
-0
slapos/recipe/template/__init__.py
slapos/recipe/template/__init__.py
+3
-0
slapos/recipe/template/jinja2_template.py
slapos/recipe/template/jinja2_template.py
+7
-2
No files found.
slapos/recipe/template/README.jinja2.txt
View file @
6e937e55
...
...
@@ -485,6 +485,53 @@ path)::
b1foo
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``
~~~~~~~~~~~~
...
...
slapos/recipe/template/__init__.py
View file @
6e937e55
...
...
@@ -61,6 +61,9 @@ def get_umask():
get_umask
=
lambda
:
umask
return
umask
def
is_true
(
value
,
default
=
False
):
return
default
if
value
is
None
else
(
'false'
,
'true'
).
index
(
value
)
class
Recipe
(
object
):
...
...
slapos/recipe/template/jinja2_template.py
View file @
6e937e55
...
...
@@ -30,7 +30,7 @@ import zc.buildout
from
jinja2
import
Environment
,
StrictUndefined
,
\
BaseLoader
,
TemplateNotFound
,
PrefixLoader
import
six
from
.
import
Recipe
from
.
import
is_true
,
Recipe
DEFAULT_CONTEXT
=
{
x
.
__name__
:
x
for
x
in
(
abs
,
all
,
any
,
bin
,
bool
,
bytes
,
callable
,
chr
,
complex
,
dict
,
divmod
,
...
...
@@ -145,6 +145,7 @@ class Recipe(Recipe):
args
=
self
.
buildout
,
name
,
options
self
.
once
=
options
.
get
(
'once'
)
self
.
encoding
=
options
.
get
(
'encoding'
,
'utf-8'
)
self
.
_update
=
is_true
(
options
.
get
(
'update'
))
import_delimiter
=
options
.
get
(
'import-delimiter'
,
DEFAULT_IMPORT_DELIMITER
)
import_dict
=
{}
...
...
@@ -223,4 +224,8 @@ class Recipe(Recipe):
return
return
installed
update
=
install
def
update
(
self
):
if
self
.
_update
:
self
.
install
()
else
:
super
(
Recipe
,
self
).
update
()
Julien Muchembled
@jm
mentioned in merge request
!8 (closed)
·
Feb 03, 2022
mentioned in merge request
!8 (closed)
mentioned in merge request !8
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment