Skip to content

Commit 03d2cb8

Browse files
ilg-uladbridge
authored andcommitted
Exporters: make jinja engine strict
- configure the jinja Environment to raise exception when substitution variables are not defined - trim spaces and lines, to avoid empty lines in generated files
1 parent c173a14 commit 03d2cb8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/export/exporters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
from os.path import join, dirname, relpath, basename, realpath, normpath
66
from itertools import groupby
7-
from jinja2 import FileSystemLoader
7+
from jinja2 import FileSystemLoader, StrictUndefined
88
from jinja2.environment import Environment
99
import copy
1010

@@ -115,7 +115,7 @@ def gen_file(self, template_file, data, target_file):
115115
"""Generates a project file from a template using jinja"""
116116
jinja_loader = FileSystemLoader(
117117
os.path.dirname(os.path.abspath(__file__)))
118-
jinja_environment = Environment(loader=jinja_loader)
118+
jinja_environment = Environment(loader=jinja_loader, undefined=StrictUndefined, trim_blocks=True, lstrip_blocks=True)
119119

120120
template = jinja_environment.get_template(template_file)
121121
target_text = template.render(data)

0 commit comments

Comments
 (0)