60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
"""Presubmit and utility scripts registered as poetry console entry points."""
|
|
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def _run(*cmd: str) -> int:
|
|
return subprocess.run(list(cmd)).returncode
|
|
|
|
|
|
def fmt():
|
|
"""Run black formatter (modify files in place)."""
|
|
sys.exit(_run("black", "."))
|
|
|
|
|
|
def presubmit():
|
|
"""Run all checks: black format check, flake8, pyright, pytest, JS lint/fmt/test.
|
|
|
|
JS lint and format checks require `npm install` to be run once first;
|
|
they are skipped (with a warning) when node_modules is absent.
|
|
"""
|
|
steps = [
|
|
["black", "--check", "."],
|
|
["flake8", "."],
|
|
["pyright"],
|
|
["pytest", "tests/"],
|
|
# JS: tests run via Node built-in runner (no npm packages needed)
|
|
["node", "--test", "tests/js/pure-functions.test.js"],
|
|
]
|
|
# JS lint/fmt require npm packages — skip gracefully if not installed
|
|
npm_steps: list[list[str]] = [
|
|
["npm", "run", "fmt:check"],
|
|
["npm", "run", "lint"],
|
|
]
|
|
|
|
failed: list[str] = []
|
|
for step in steps:
|
|
if subprocess.run(step).returncode != 0:
|
|
failed.append(" ".join(step))
|
|
|
|
if Path("node_modules").exists():
|
|
for step in npm_steps:
|
|
if subprocess.run(step).returncode != 0:
|
|
failed.append(" ".join(step))
|
|
else:
|
|
print(
|
|
"\nSkipping JS lint/fmt: run `npm install` to enable these checks.",
|
|
file=sys.stderr,
|
|
)
|
|
|
|
if failed:
|
|
print(f"\nFailed: {', '.join(failed)}", file=sys.stderr)
|
|
sys.exit(1)
|
|
print("\nAll presubmit checks passed.")
|
|
print(
|
|
"\nReminder: if this task changed architecture, layer boundaries, config schema,\n"
|
|
"directory layout, API endpoints, or the plugin system — update docs/overview.md."
|
|
)
|