"""Portable repository checks for Project Calendar.""" from __future__ import annotations import compileall import json import re import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] PYTHON_FILES = [ "app.py", "config.py", "excel_export.py", "gantt_renderer.py", "jira_client.py", "scripts/check.py", ] JSON_FILES = [ "country_assignments.json", "pm_assignments.json", "pm_backup_assignments.json", "research_backup_assignments.json", ] def _requirement_name(line: str) -> str: line = line.strip() for marker in ["==", ">=", "<=", "~=", "!=", ">", "<"]: if marker in line: return line.split(marker, 1)[0].strip().lower().replace("_", "-") return line.lower().replace("_", "-") def check_python_compile() -> bool: return compileall.compile_file( str(ROOT / "app.py"), quiet=1, force=True ) and all( compileall.compile_file(str(ROOT / relative_path), quiet=1, force=True) for relative_path in PYTHON_FILES if relative_path != "app.py" ) def check_json_files() -> list[str]: errors: list[str] = [] for relative_path in JSON_FILES: path = ROOT / relative_path try: with path.open("r", encoding="utf-8") as handle: data = json.load(handle) except Exception as exc: errors.append(f"{relative_path}: {exc}") continue if not isinstance(data, dict): errors.append(f"{relative_path}: expected top-level object") return errors def check_dependency_lock() -> list[str]: requirements_path = ROOT / "requirements.txt" lock_path = ROOT / "requirements-lock.txt" if not lock_path.exists(): return ["requirements-lock.txt: missing lockfile"] direct_requirements = { _requirement_name(line) for line in requirements_path.read_text(encoding="utf-8").splitlines() if line.strip() and not line.strip().startswith("#") } locked_requirements = { _requirement_name(line) for line in lock_path.read_text(encoding="utf-8").splitlines() if line.strip() and not line.strip().startswith("#") } missing = sorted(direct_requirements - locked_requirements) return [f"requirements-lock.txt: missing pin for {name}" for name in missing] def check_standards_sync_note() -> list[str]: path = ROOT / ".agents" / "policies" / "standards-sync.md" if not path.exists(): return [".agents/policies/standards-sync.md: missing"] text = path.read_text(encoding="utf-8") errors: list[str] = [] if not re.search(r"Ref observed locally:\s*`?[0-9a-f]{7,40}`?", text): errors.append("standards-sync.md: missing applied standards ref") standards_path = Path(r"C:\Users\JulianeMatussek\decode-ai-standards") if standards_path.exists() and not (standards_path / ".git").exists(): errors.append("standards-sync.md: local standards path exists but is not a git checkout") return errors def main() -> int: ok = True if not check_python_compile(): print("Python compile check failed", file=sys.stderr) ok = False json_errors = check_json_files() for error in json_errors: print(error, file=sys.stderr) if json_errors: ok = False lock_errors = check_dependency_lock() for error in lock_errors: print(error, file=sys.stderr) if lock_errors: ok = False sync_errors = check_standards_sync_note() for error in sync_errors: print(error, file=sys.stderr) if sync_errors: ok = False tests = subprocess.run( [sys.executable, "-m", "unittest", "discover", "-s", "tests"], cwd=ROOT, check=False, ) if tests.returncode != 0: ok = False if ok: print("All local checks passed") return 0 return 1 if __name__ == "__main__": raise SystemExit(main())