Skip to content

Commit 2a09b52

Browse files
committed
Allow for macros and error checks in SUIT manifests templates
Ref: NCSSDK-NONE Signed-off-by: Artur Hadasz <[email protected]>
1 parent 0a8712a commit 2a09b52

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ncs/build.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import logging
1414
import yaml
1515

16-
from jinja2 import Template
16+
from jinja2 import FileSystemLoader, Environment
17+
from jinja2.exceptions import TemplateRuntimeError
1718
from argparse import ArgumentParser
1819
from configparser import ConfigParser
1920

@@ -157,11 +158,17 @@ def read_version_file(version_file):
157158
return cfg.items("VERSION")
158159
return {}
159160

161+
def raise_helper(msg):
162+
raise TemplateRuntimeError(msg)
160163

161164
def render_template(template_location, data):
162165
"""Render template using passed data."""
163-
with open(template_location) as template_file:
164-
template = Template(template_file.read())
166+
macros_path = pathlib.Path(dir_path.parent.parent.parent.parent / "nrf" / "config" / "suit" / "macros").absolute()
167+
template_location = pathlib.Path(template_location)
168+
env = Environment(loader=FileSystemLoader([macros_path, template_location.parent]), trim_blocks=False, lstrip_blocks=False)
169+
env.globals['raise_err'] = raise_helper
170+
171+
template = env.get_template(template_location.name)
165172
return template.render(data)
166173

167174

0 commit comments

Comments
 (0)