General optimations and debugging

This commit is contained in:
2025-07-08 13:50:23 +02:00
parent cb29a479b3
commit 36ff93e64e
69 changed files with 425 additions and 290 deletions

View File

@@ -7,12 +7,11 @@ class TestJinjaIncludePaths(unittest.TestCase):
Verifies that in all .j2 files in the project (root + subfolders):
- Every {% include 'string/path' %} or {% include "string/path" %} refers to an existing file.
- Any include using a variable or concatenation is ignored.
- Includes are resolved relative to project root, template directory, or file's parent.
"""
PROJECT_ROOT = Path(__file__).resolve().parents[2]
# Fängt jede include-Direktive ein (den gesamten Ausdruck zwischen include und %})
INCLUDE_STMT_RE = re.compile(r"{%\s*include\s+(.+?)\s*%}")
# Erlaubt nur ein einzelnes String-Literal (Gänse- oder einfache Anführungszeichen)
LITERAL_PATH_RE = re.compile(r"^['\"]([^'\"]+)['\"]$")
LITERAL_PATH_RE = re.compile(r"^[\'\"]([^\'\"]+)[\'\"]$")
def test_all_jinja_includes_exist(self):
template_paths = list(self.PROJECT_ROOT.glob("**/*.j2"))
@@ -28,17 +27,33 @@ class TestJinjaIncludePaths(unittest.TestCase):
expr = stmt.group(1).strip()
m = self.LITERAL_PATH_RE.match(expr)
if not m:
continue # Variable-based includes ignorieren
continue # ignore variable-based includes
include_path = m.group(1)
abs_target = self.PROJECT_ROOT / include_path
rel_target = tpl.parent / include_path
# check absolute project-relative path
abs_target = self.PROJECT_ROOT / include_path
# check path relative to the template file
rel_target = tpl.parent / include_path
if not (abs_target.exists() or rel_target.exists()):
# check path relative to role's templates directory
role_templates_root = None
for parent in tpl.parents:
if parent.name == 'templates':
role_templates_root = parent
break
role_target = None
if role_templates_root:
role_target = role_templates_root / include_path
if not (
abs_target.exists() or
rel_target.exists() or
(role_target and role_target.exists())
):
rel_tpl = tpl.relative_to(self.PROJECT_ROOT)
missing.append(
f"{rel_tpl}: included file '{include_path}' not found "
f"(neither in PROJECT_ROOT nor in {tpl.parent.relative_to(self.PROJECT_ROOT)})"
f"(checked in project root, {tpl.parent.relative_to(self.PROJECT_ROOT)} or templates folder)"
)
if missing: