repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

scripts/mdslw.py

Raw
#!/usr/bin/env python3
"""Run mdslw on repo Markdown with repo-local ignores."""

from __future__ import annotations

import argparse
import subprocess
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
SKIP_DIRS = {".git", ".jj", ".demo", "node_modules", "__pycache__"}
SKIP_FILES = {
    Path("extensions/TODO.md"),
    Path("skills/pi/LICENSE.md"),
}


def markdown_files() -> list[str]:
    result: list[str] = []
    for path in sorted(ROOT.rglob("*.md")):
        rel = path.relative_to(ROOT)
        if rel in SKIP_FILES or any(part in SKIP_DIRS for part in rel.parts):
            continue
        if path.is_symlink():
            continue
        result.append(str(rel))
    return result


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--mode", choices=["format", "check", "both"], default="format")
    args = parser.parse_args()

    files = markdown_files()
    if not files:
        return 0
    return subprocess.run(["mdslw", "--mode", args.mode, *files], cwd=ROOT, check=False).returncode


if __name__ == "__main__":
    raise SystemExit(main())