#!/usr/bin/env python3
"""Format all tracked Python files using the repo's YAPF style.

This script intentionally formats only files tracked by git to avoid touching
files that are ignored (e.g., venv, site-packages).
"""
import subprocess
import sys

try:
    out = subprocess.check_output(["git", "ls-files", "*.py"]).decode("utf-8")
except subprocess.CalledProcessError as exc:
    print("Failed to get tracked files from git:", exc, file=sys.stderr)
    sys.exit(1)

files = [f for f in (line.strip() for line in out.splitlines()) if f]
print(f"Formatting {len(files)} tracked python files...")
if not files:
    print("No tracked python files found.")
    sys.exit(0)

for path in files:
    print(path)
    subprocess.run([sys.executable, "-m", "yapf", "-i", "--style", ".style.yapf", path], check=False)

print("Done")
