diff --git a/CHANGES.txt b/CHANGES.txt index 2922c24d378fc121402a3821416560a6ed874b5b..7ed2fcbe1f12eb6c4f1b5e51c9d57e2da9fac170 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 ============= diff --git a/mkexp b/mkexp index 2923d35789cecb8865a75b39838e9b6ee8b32777..1411c26286f5ddebfcedc9f9fd318323691a090a 100755 --- a/mkexp +++ b/mkexp @@ -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):