Skip to content
Snippets Groups Projects
Commit 16531a2f authored by Karl-Hermann Wieners's avatar Karl-Hermann Wieners
Browse files

mkexp: handle deprecation warnings for versions 3+ of Jinja2

The global/filter/test decorators were re-named, the old names are deprecated
parent ac3505e6
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ Global
* Fixes related to python3, perl-5.26, and jinja2-3.0 compatibility
* Added tools to manage differences/similarities between config files
(compconfig.py, diffconfig.py, unmergeconfig)
* Handle deprecation warnings for versions 3+ of Jinja2
Release 1.1.2
=============
......
......@@ -292,10 +292,21 @@ template_env = Environment(
extensions = ['jinja2.ext.do']
)
# Check decorator compatibility for 3+ versions of Jinja2
if 'pass_context' in dir(jinja2):
pass_context = jinja2.pass_context
pass_environment = jinja2.pass_environment
pass_eval_context = jinja2.pass_eval_context
else:
pass_context = jinja2.contextfunction
pass_environment = jinja2.environmentfilter
pass_eval_context = jinja2.evalcontextfilter
# Additional global functions
# - Helper function to get context information within templates
@jinja2.contextfunction
@pass_context
def get_context(ctx, key=None):
return ctx.resolve(key) if key else ctx
template_env.globals['context'] = get_context
......@@ -310,7 +321,7 @@ template_env.globals['format_namelist'] = format_namelist
# Additional filters
# - A better wordwrap filter
@jinja2.environmentfilter
@pass_environment
def wordwrap(env, s, width=79, break_long_words=True, break_on_hyphens=True,
wrapstring=None):
if wrapstring is None:
......@@ -337,7 +348,7 @@ template_env.filters['filter'] = lambda x, f=None: list(filter(f, x))
# - Replace 'list' handling simple values and strings as singleton lists
list_original = template_env.filters['list']
@jinja2.evalcontextfilter
@pass_eval_context
def list_singleton(eval_ctx, x, keep_empty=False, *args, **kwargs):
# Workaround for 2.8 bug when applied to literals
if isinstance(x, jinja2.nodes.EvalContext):
......@@ -353,7 +364,7 @@ template_env.filters['list'] = list_singleton
# - Replace 'join' handling simple values and strings as singleton lists
join_original = template_env.filters['join']
@jinja2.evalcontextfilter
@pass_eval_context
def join_singleton(eval_ctx, x, *args, **kwargs):
# Workaround for 2.8 bug when applied to literals
if isinstance(x, jinja2.nodes.EvalContext):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment