Initial commit
Photo-based book cataloger with AI identification. Room → Cabinet → Shelf → Book hierarchy; FastAPI + SQLite backend; vanilla JS SPA; OpenAI-compatible plugin system for boundary detection, text recognition, and archive search.
This commit is contained in:
55
scripts/presubmit.py
Normal file
55
scripts/presubmit.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""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.")
|
||||
Reference in New Issue
Block a user