#!/usr/bin/env python3 from __future__ import annotations import subprocess import tomllib from pathlib import Path ROOT = Path(__file__).resolve().parent WORKSPACE_MANIFEST = ROOT / "Cargo.toml" DEFAULT_CLIPPY = ["cargo", "clippy", "--workspace", "--all-targets", "--all-features"] def run(argv: list[str]) -> None: print("+", " ".join(argv), flush=True) proc = subprocess.run(argv, cwd=ROOT) if proc.returncode != 0: raise SystemExit(proc.returncode) def normalized_clippy_command() -> list[str]: workspace = tomllib.loads(WORKSPACE_MANIFEST.read_text(encoding="utf-8")) metadata = ( workspace.get("workspace", {}) .get("metadata", {}) .get("adequate-rust-mcp", {}) ) configured = metadata.get("clippy_command") if not ( isinstance(configured, list) and configured and all(isinstance(part, str) for part in configured) ): return DEFAULT_CLIPPY # Human check output does not need machine JSON framing. command: list[str] = [] skip_next = False for index, part in enumerate(configured): if skip_next: skip_next = False continue if part.startswith("--message-format="): continue if part == "--message-format" and index + 1 < len(configured): skip_next = True continue command.append(part) return command or DEFAULT_CLIPPY def main() -> None: run(["cargo", "fmt", "--all", "--check"]) run(normalized_clippy_command()) run(["cargo", "test", "--workspace", "--all-targets", "--all-features"]) if __name__ == "__main__": try: main() except KeyboardInterrupt: raise SystemExit(130)