File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313import logging
1414import yaml
1515
16- from jinja2 import Template
16+ from jinja2 import FileSystemLoader , Environment
17+ from jinja2 .exceptions import TemplateRuntimeError
1718from argparse import ArgumentParser
1819from configparser import ConfigParser
1920
@@ -158,10 +159,21 @@ def read_version_file(version_file):
158159 return {}
159160
160161
162+ def raise_helper (msg ):
163+ """Raise an error as a result of the raise_err directive the template."""
164+ raise TemplateRuntimeError (msg )
165+
166+
161167def render_template (template_location , data ):
162168 """Render template using passed data."""
163- with open (template_location ) as template_file :
164- template = Template (template_file .read ())
169+ macros_path = pathlib .Path (dir_path .parent .parent .parent .parent / "nrf" / "config" / "suit" / "macros" ).absolute ()
170+ template_location = pathlib .Path (template_location )
171+ env = Environment (
172+ loader = FileSystemLoader ([macros_path , template_location .parent ]), trim_blocks = False , lstrip_blocks = False
173+ )
174+ env .globals ["raise_err" ] = raise_helper
175+
176+ template = env .get_template (template_location .name )
165177 return template .render (data )
166178
167179
You can’t perform that action at this time.
0 commit comments