]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add _common dir to jinja2 template loader
authorNicki Křížek <nicki@isc.org>
Tue, 7 Apr 2026 12:43:11 +0000 (14:43 +0200)
committerNicki Křížek <nicki@isc.org>
Thu, 28 May 2026 14:52:24 +0000 (16:52 +0200)
This allows include of template snippets from _common/ directory.

(cherry picked from commit e34c3252d973ca6e1eb62b66ca74599568e8d33c)

bin/tests/system/isctest/template.py

index 845a372da4612795ba1f3771cdcd62001a5fa46f..6f3dd142260377b2fc4a8772413e373694e28362 100644 (file)
@@ -55,9 +55,13 @@ class TemplateEngine:
             except ImportError:
                 pytest.skip("jinja2 not found")
 
-            loader = jinja2.FileSystemLoader(str(self.directory))
             self._j2env = jinja2.Environment(
-                loader=loader,
+                loader=jinja2.FileSystemLoader(
+                    [
+                        str(self.directory),
+                        str(ALL["srcdir"]),  # to allow _common/ includes
+                    ]
+                ),
                 undefined=jinja2.StrictUndefined,
                 variable_start_string="@",
                 variable_end_string="@",
@@ -83,12 +87,13 @@ class TemplateEngine:
         variables which the engine was initialized with are also filled in. In
         case of a variable name clash, `data` has precedence.
         """
+        available = self.j2env.list_templates()
         if template is None:
             template = f"{output}.j2.manual"
-            if not Path(template).is_file():
+            if template not in available:
                 template = f"{output}.j2"
-        if not Path(template).is_file():
-            raise RuntimeError('No jinja2 template found for "{output}"')
+        if template not in available:
+            raise RuntimeError(f'No jinja2 template found for "{output}"')
 
         if data is None:
             data = {**self.env_vars}