From 7020082856f36e06eb3e970155ca6e2eeafe5c7c Mon Sep 17 00:00:00 2001 From: Dominik Holland Date: Wed, 22 Jan 2020 13:01:19 +0100 Subject: ivigenerator: Fix the jinja_error global function When splitting the generator into multiple files, the needed imports were not added to global_function.py. This also retrieves the current qface file from the jinja context, instead of using a global variable. Change-Id: I7ec608e758a69192d360404623f6a6f54908f29c Reviewed-by: Robert Griebl --- src/tools/ivigenerator/generator/global_functions.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/tools/ivigenerator/generator/global_functions.py b/src/tools/ivigenerator/generator/global_functions.py index 6794fc5..1ef8b60 100644 --- a/src/tools/ivigenerator/generator/global_functions.py +++ b/src/tools/ivigenerator/generator/global_functions.py @@ -39,6 +39,12 @@ # # SPDX-License-Identifier: LGPL-3.0 +import inspect +import click + +from jinja2 import TemplateAssertionError +from jinja2 import contextfunction + def jinjaTrace(): """ Collects all jinja template files and the line numbers from the current calltrace @@ -53,7 +59,8 @@ def jinjaTrace(): return infos -def jinja_error(msg): +@contextfunction +def jinja_error(context, msg): """ Throws an error for the current jinja template and the templates this is included from This can be used inside a filter to indicate problems with the passed arguments or direclty inside @@ -65,7 +72,7 @@ def jinja_error(msg): if len(infos) > 1: for info in infos[1:]: message = message + "\n{0}:{1}: instantiated from here".format(info[0], info[1]) - message = message + "\n{0}: instantiated from here".format(currentQFaceSrcFile) + message = message + "\n{0}: instantiated from here".format(context["srcFile"]) raise TemplateAssertionError(message, infos[0][1], "", infos[0][0]) raise TemplateAssertionError(msg, -1, "", "unknown") -- cgit v1.2.1