Skip to content

Commit e4bd6f4

Browse files
committed
Merge pull request #444 from chrta/enable_jinja_template_inheritance
Enable the use of template inheritance for exporters
2 parents e91e6e6 + cc09416 commit e4bd6f4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

workspace_tools/export/exporters.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from os import walk, remove
44
from os.path import join, dirname, isdir, split
55
from copy import copy
6-
from jinja2 import Template
6+
from jinja2 import Template, FileSystemLoader
7+
from jinja2.environment import Environment
78
from contextlib import closing
89
from zipfile import ZipFile, ZIP_DEFLATED
910

@@ -23,6 +24,8 @@ def __init__(self, target, inputDir, program_name, build_url_resolver):
2324
self.program_name = program_name
2425
self.toolchain = TOOLCHAIN_CLASSES[self.get_toolchain()](TARGET_MAP[target])
2526
self.build_url_resolver = build_url_resolver
27+
jinja_loader = FileSystemLoader(os.path.dirname(os.path.abspath(__file__)))
28+
self.jinja_environment = Environment(loader=jinja_loader)
2629

2730
def get_toolchain(self):
2831
return self.TOOLCHAIN
@@ -87,8 +90,7 @@ def scan_and_copy_resources(self, prj_path, trg_path):
8790

8891
def gen_file(self, template_file, data, target_file):
8992
template_path = join(Exporter.TEMPLATE_DIR, template_file)
90-
template_text = open(template_path).read()
91-
template = Template(template_text)
93+
template = self.jinja_environment.get_template(template_file)
9294
target_text = template.render(data)
9395

9496
target_path = join(self.inputDir, target_file)

0 commit comments

Comments
 (0)