# SPDX-License-Identifier: Apache-2.0
# Developer commands. Everything runs through uv (https://docs.astral.sh/uv/) with the locked versions in uv.lock.
.DEFAULT_GOAL := help
SHELL := bash
UNAME := $(shell uname -sm)
# The narration extra for this computer: MLX on Apple Silicon, Kokoro on PyTorch on Linux. Intel Macs have no
# supported voice backend (see README, Requirements).
ifeq ($(UNAME),Darwin arm64)
VOICE_EXTRA := --extra mlx
else ifeq ($(firstword $(UNAME)),Linux)
VOICE_EXTRA := --extra kokoro --extra whisper
else
VOICE_EXTRA :=
endif
EXAMPLE := examples/mars-climate-orbiter/spec.yaml

.PHONY: help setup setup-dev test test-all lint format type schema check render-example scan plugin-check clean

help: ## list the commands
	@grep -E '^[a-z-]+:.*## ' $(MAKEFILE_LIST) | awk -F':.*## ' '{printf "  make %-15s %s\n", $$1, $$2}'

setup: ## install everything to render: Python env with a voice, render runtime + headless Chrome
	@test -n "$(VOICE_EXTRA)" || echo "warning: no voice backend for $(UNAME); narration needs Apple Silicon or Linux"
	uv sync $(VOICE_EXTRA)
	uv run citefilm runtime install
	uv run citefilm doctor

setup-dev: ## developer setup without the speech models (enough for lint, types and the fast tests)
	uv sync
	uvx pre-commit install

test: ## fast tests (no browser, no speech model)
	uv run pytest

test-all: ## every test: fast + real renders + real speech workers (needs `make setup`), with coverage
	uv run pytest -m "" --cov --cov-report=term

lint: ## ruff lint + format check + repository hygiene
	uv run ruff check .
	uv run ruff format --check .
	uv run python scripts/check_hygiene.py

format: ## format and auto-fix
	uv run ruff format .
	uv run ruff check --fix .

type: ## mypy --strict
	uv run mypy

schema: ## regenerate schema/spec.schema.json from the models
	uv run citefilm schema --output schema/spec.schema.json

check: lint type test ## everything CI runs (except real renders)

render-example: ## render the example film into out/mars-climate-orbiter/
	uv run citefilm validate $(EXAMPLE)
	time uv run citefilm build $(EXAMPLE)

scan: ## secret + privacy scan of the files and the whole git history
	uv run python scripts/check_hygiene.py --history
	uvx pre-commit run gitleaks --all-files

plugin-check: ## validate the Claude Code plugin and marketplace manifests (needs the claude CLI)
	claude plugin validate . --strict

clean: ## remove build output and caches (not out/)
	rm -rf build dist .pytest_cache .ruff_cache .mypy_cache .hypothesis .coverage coverage.xml htmlcov
