"""Script to run all linters and formatters on the graph directory."""
import subprocess
def run_command(name: str, cmd: list[str]) -> None:
"""Run a subprocess command and print output or errors."""
print(f"Running {name}...")
try:
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
print(e.stdout)
print(e.stderr)
print(f"\n{name} failed with exit code {e.returncode}:")
raise
print(result.stdout)
def run_black() -> None:
"""Run Black formatter on the src and tests directories."""
run_command(
"Black",
["black", "src"],
)
def run_isort() -> None:
"""Run isort formatter on the src and tests directories."""
run_command(
"isort",
["isort", "src"],
)
def run_mypy() -> None:
"""Run MyPy type checker on the src and tests directories."""
run_command(
"MyPy",
["mypy", "src"],
)
def run_pylint() -> None:
"""Run Pylint linter on the src and tests directories."""
run_command(
"Pylint",
["pylint", "src"],
)
def run() -> None:
"""Run all linters and formatters on the src directory."""
run_black()
run_isort()
run_mypy()
run_pylint()
if __name__ == "__main__":
run()