| 12345678910111213141516171819202122232425262728 |
- """Check Python 3.11 syntax in lesson snippets without executing services."""
- import ast
- import json
- from pathlib import Path
- root = Path(__file__).resolve().parents[1]
- files = [root / "app/lessons.json", *sorted((root / "public/content").glob("*.json"))]
- checked = 0
- errors = []
- for path in files:
- lessons = json.loads(path.read_text(encoding="utf-8-sig"))
- for lesson in lessons:
- for index, step in enumerate(lesson["steps"], 1):
- if step.get("lang") not in {"python", "py"} or not step.get("code"):
- continue
- label = f"{path.stem}/{lesson['id']}/step-{index}"
- try:
- ast.parse(step["code"], filename=label, feature_version=(3, 11))
- checked += 1
- except SyntaxError as exc:
- errors.append(f"{label}: line {exc.lineno}: {exc.msg}")
- if errors:
- raise SystemExit("\n".join(errors))
- print(f"Python 3.11 AST: {checked} snippets passed across {len(files)} modules.")
- print("Syntax only; dependencies, SQL, external services and failure drills are not executed.")
|