From 407ef72909f68f919d19e57f93be6239c6a32243 Mon Sep 17 00:00:00 2001 From: cmoineau <cyril.moineau@cea.fr> Date: Tue, 9 Jul 2024 09:23:46 +0000 Subject: [PATCH] Jinja code generation function raise error if args not provided. --- aidge_core/export_utils/code_generation.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/aidge_core/export_utils/code_generation.py b/aidge_core/export_utils/code_generation.py index a02fc0966..29b24bb82 100644 --- a/aidge_core/export_utils/code_generation.py +++ b/aidge_core/export_utils/code_generation.py @@ -1,5 +1,5 @@ from pathlib import Path -from jinja2 import Environment, FileSystemLoader +from jinja2 import Environment, FileSystemLoader, StrictUndefined from typing import Union @@ -21,13 +21,9 @@ def generate_file(file_path: Union[Path, str], template_path: Union[Path, str], # Make dir file_path.parent.mkdir(parents=True, exist_ok=True) - # Select template - template = Environment(loader=FileSystemLoader( - template_path.parent)).get_template(template_path.name) - # Generate file with open(file_path, mode="w", encoding="utf-8") as file: - file.write(template.render(kwargs)) + file.write(generate_str(template_path, **kwargs)) def generate_str(template_path: Union[Path, str], **kwargs) -> str: @@ -43,4 +39,4 @@ def generate_str(template_path: Union[Path, str], **kwargs) -> str: if isinstance(template_path, str): template_path = Path(template_path) return Environment(loader=FileSystemLoader( - template_path.parent)).get_template(template_path.name).render(kwargs) + template_path.parent), undefined=StrictUndefined).get_template(template_path.name).render(kwargs) -- GitLab