| 
29 | 29 | from ..ctl.generator import run as run_generator  | 
30 | 30 | from ..ctl.menu import app as menu_app  | 
31 | 31 | from ..ctl.object import app as object_app  | 
32 |  | -from ..ctl.render import list_jinja2_transforms  | 
 | 32 | +from ..ctl.render import list_jinja2_transforms, print_template_errors  | 
33 | 33 | from ..ctl.repository import app as repository_app  | 
34 | 34 | from ..ctl.repository import get_repository_config  | 
35 | 35 | from ..ctl.schema import app as schema_app  | 
 | 
44 | 44 | from ..exceptions import GraphQLError, ModuleImportError  | 
45 | 45 | from ..schema import MainSchemaTypesAll, SchemaRoot  | 
46 | 46 | from ..template import Jinja2Template  | 
47 |  | -from ..template.exceptions import (  | 
48 |  | -    JinjaTemplateError,  | 
49 |  | -    JinjaTemplateNotFoundError,  | 
50 |  | -    JinjaTemplateSyntaxError,  | 
51 |  | -    JinjaTemplateUndefinedError,  | 
52 |  | -)  | 
 | 47 | +from ..template.exceptions import JinjaTemplateError  | 
53 | 48 | from ..utils import get_branch, write_to_file  | 
54 | 49 | from ..yaml import SchemaFile  | 
55 | 50 | from .exporter import dump  | 
@@ -172,50 +167,22 @@ async def run(  | 
172 | 167 |         raise typer.Abort(f"Unable to Load the method {method} in the Python script at {script}")  | 
173 | 168 | 
 
  | 
174 | 169 |     client = initialize_client(  | 
175 |  | -        branch=branch, timeout=timeout, max_concurrent_execution=concurrent, identifier=module_name  | 
 | 170 | +        branch=branch,  | 
 | 171 | +        timeout=timeout,  | 
 | 172 | +        max_concurrent_execution=concurrent,  | 
 | 173 | +        identifier=module_name,  | 
176 | 174 |     )  | 
177 | 175 |     func = getattr(module, method)  | 
178 | 176 |     await func(client=client, log=log, branch=branch, **variables_dict)  | 
179 | 177 | 
 
  | 
180 | 178 | 
 
  | 
181 | 179 | async def render_jinja2_template(template_path: Path, variables: dict[str, Any], data: dict[str, Any]) -> str:  | 
182 |  | -    if not template_path.is_file():  | 
183 |  | -        console.print(f"[red]Unable to locate the template at {template_path}")  | 
184 |  | -        raise typer.Exit(1)  | 
185 |  | - | 
186 | 180 |     variables["data"] = data  | 
187 | 181 |     jinja_template = Jinja2Template(template=Path(template_path), template_directory=Path())  | 
188 | 182 |     try:  | 
189 | 183 |         rendered_tpl = await jinja_template.render(variables=variables)  | 
190 |  | -    except JinjaTemplateNotFoundError as exc:  | 
191 |  | -        console.print("[red]An error occurred while rendering the jinja template")  | 
192 |  | -        console.print("")  | 
193 |  | -        if exc.base_template:  | 
194 |  | -            console.print(f"Base template: [yellow]{exc.base_template}")  | 
195 |  | -        console.print(f"Missing template: [yellow]{exc.filename}")  | 
196 |  | -        raise typer.Exit(1) from exc  | 
197 |  | - | 
198 |  | -    except JinjaTemplateUndefinedError as exc:  | 
199 |  | -        console.print("[red]An error occurred while rendering the jinja template")  | 
200 |  | -        for error in exc.errors:  | 
201 |  | -            console.print(f"[yellow]{error.frame.filename} on line {error.frame.lineno}\n")  | 
202 |  | -            console.print(error.syntax)  | 
203 |  | -        console.print("")  | 
204 |  | -        console.print(exc.message)  | 
205 |  | -        raise typer.Exit(1) from exc  | 
206 |  | -    except JinjaTemplateSyntaxError as exc:  | 
207 |  | -        console.print("[red]A syntax error was encountered within the template")  | 
208 |  | -        console.print("")  | 
209 |  | -        if exc.filename:  | 
210 |  | -            console.print(f"Filename: [yellow]{exc.filename}")  | 
211 |  | -        console.print(f"Line number: [yellow]{exc.lineno}")  | 
212 |  | -        console.print()  | 
213 |  | -        console.print(exc.message)  | 
214 |  | -        raise typer.Exit(1) from exc  | 
215 | 184 |     except JinjaTemplateError as exc:  | 
216 |  | -        console.print("[red]An error occurred while rendering the jinja template")  | 
217 |  | -        console.print("")  | 
218 |  | -        console.print(f"[yellow]{exc.message}")  | 
 | 185 | +        print_template_errors(error=exc, console=console)  | 
219 | 186 |         raise typer.Exit(1) from exc  | 
220 | 187 | 
 
  | 
221 | 188 |     return rendered_tpl  | 
@@ -244,7 +211,11 @@ async def _run_transform(  | 
244 | 211 | 
 
  | 
245 | 212 |     try:  | 
246 | 213 |         response = execute_graphql_query(  | 
247 |  | -            query=query_name, variables_dict=variables, branch=branch, debug=debug, repository_config=repository_config  | 
 | 214 | +            query=query_name,  | 
 | 215 | +            variables_dict=variables,  | 
 | 216 | +            branch=branch,  | 
 | 217 | +            debug=debug,  | 
 | 218 | +            repository_config=repository_config,  | 
248 | 219 |         )  | 
249 | 220 | 
 
  | 
250 | 221 |         # TODO: response is a dict and can't be printed to the console in this way.  | 
@@ -427,7 +398,10 @@ def version() -> None:  | 
427 | 398 | 
 
  | 
428 | 399 | @app.command(name="info")  | 
429 | 400 | @catch_exception(console=console)  | 
430 |  | -def info(detail: bool = typer.Option(False, help="Display detailed information."), _: str = CONFIG_PARAM) -> None:  # noqa: PLR0915  | 
 | 401 | +def info(  # noqa: PLR0915  | 
 | 402 | +    detail: bool = typer.Option(False, help="Display detailed information."),  | 
 | 403 | +    _: str = CONFIG_PARAM,  | 
 | 404 | +) -> None:  | 
431 | 405 |     """Display the status of the Python SDK."""  | 
432 | 406 | 
 
  | 
433 | 407 |     info: dict[str, Any] = {  | 
@@ -493,10 +467,14 @@ def info(detail: bool = typer.Option(False, help="Display detailed information."  | 
493 | 467 |         infrahub_info = Table(show_header=False, box=None)  | 
494 | 468 |         if info["user_info"]:  | 
495 | 469 |             infrahub_info.add_row("User:", info["user_info"]["AccountProfile"]["display_label"])  | 
496 |  | -            infrahub_info.add_row("Description:", info["user_info"]["AccountProfile"]["description"]["value"])  | 
 | 470 | +            infrahub_info.add_row(  | 
 | 471 | +                "Description:",  | 
 | 472 | +                info["user_info"]["AccountProfile"]["description"]["value"],  | 
 | 473 | +            )  | 
497 | 474 |             infrahub_info.add_row("Status:", info["user_info"]["AccountProfile"]["status"]["label"])  | 
498 | 475 |             infrahub_info.add_row(  | 
499 |  | -                "Number of Groups:", str(info["user_info"]["AccountProfile"]["member_of_groups"]["count"])  | 
 | 476 | +                "Number of Groups:",  | 
 | 477 | +                str(info["user_info"]["AccountProfile"]["member_of_groups"]["count"]),  | 
500 | 478 |             )  | 
501 | 479 | 
 
  | 
502 | 480 |             if groups := info["groups"]:  | 
 | 
0 commit comments