mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 02:54:26 +00:00
3529 invalid comments in 528 files, grandfathered in while the linter only saw the working-tree diff. Removal ran through the linter's own collectors, so detection and deletion cannot drift: a comment whose opener line is blank before it and whose closer line is blank after it loses all its lines, anything else loses only the comment region, and a line left holding a bare delimiter goes with it. Five files keep their comments behind a nocheck marker instead. Four are upstream configs whose inline docs are upstream's own (mautrix, systemd journald, nextcloud-oidc-login, MediaWiki). In littlejs the commented-out entries ARE the deactivation mechanism for an example tile, so deleting them would delete configuration. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
75 lines
2.0 KiB
Python
Executable File
75 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import argparse
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from . import PROJECT_ROOT
|
|
|
|
INCLUDE_RE = re.compile(r"^(\s*)\{%\s*include\s*['\"]([^'\"]+)['\"]\s*%\}")
|
|
|
|
|
|
def expand_includes(rel_path, seen=None):
|
|
"""
|
|
Liest die Datei rel_path (relative zum PROJECT_ROOT),
|
|
ersetzt rekursiv alle "{% include 'path' %}"-Zeilen durch den
|
|
Inhalt der jeweiligen Datei (mit gleicher Einrückung).
|
|
"""
|
|
if seen is None:
|
|
seen = set()
|
|
rp = rel_path.replace("\\", "/")
|
|
if rp in seen:
|
|
raise RuntimeError(f"Circular include detected: {rp}")
|
|
seen.add(rp)
|
|
|
|
abs_path = str(PROJECT_ROOT / rp)
|
|
if not Path(abs_path).is_file():
|
|
raise FileNotFoundError(f"Template not found: {rp}")
|
|
|
|
output_lines = []
|
|
with Path(abs_path).open(encoding="utf-8") as f:
|
|
for line in f:
|
|
m = INCLUDE_RE.match(line)
|
|
if not m:
|
|
output_lines.append(line.rstrip("\n"))
|
|
else:
|
|
indent, inc_rel = m.group(1), m.group(2)
|
|
output_lines.extend(
|
|
indent + inc_line for inc_line in expand_includes(inc_rel, seen)
|
|
)
|
|
seen.remove(rp)
|
|
return output_lines
|
|
|
|
|
|
def parse_args():
|
|
p = argparse.ArgumentParser(
|
|
description="Expand all {% include '...' %} directives in a Jinja2 template (no variable rendering)."
|
|
)
|
|
p.add_argument("template", help="Template path relative to project root")
|
|
p.add_argument(
|
|
"--out",
|
|
help="If given, write output to this file instead of stdout",
|
|
default=None,
|
|
)
|
|
return p.parse_args()
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
|
|
try:
|
|
lines = expand_includes(args.template)
|
|
text = "\n".join(lines)
|
|
if args.out:
|
|
with Path(args.out).open("w", encoding="utf-8") as f:
|
|
f.write(text + "\n")
|
|
else:
|
|
print(text)
|
|
except Exception as e:
|
|
sys.stderr.write(f"Error: {e}\n")
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|