diff options
author | Dominik Holland <dominik.holland@qt.io> | 2020-01-22 13:01:19 +0100 |
---|---|---|
committer | Dominik Holland <dominik.holland@qt.io> | 2020-01-22 17:04:00 +0100 |
commit | 7020082856f36e06eb3e970155ca6e2eeafe5c7c (patch) | |
tree | 743c4e0349146168765745cbcb39c76a802d8653 | |
parent | 5a37ae2620e7bb74760fe3ed435c1d5e1ce63232 (diff) | |
download | qtivi-7020082856f36e06eb3e970155ca6e2eeafe5c7c.tar.gz |
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 <robert.griebl@qt.io>
-rw-r--r-- | src/tools/ivigenerator/generator/global_functions.py | 11 |
1 files 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") |