# Convenience targets. Override the interpreter with e.g. `make test PY=./venv/bin/python`.
PY ?= python

.PHONY: help install dev saip test cov run init-db profile clean

help:
	@echo "Targets:"
	@echo "  install   Install runtime dependencies"
	@echo "  dev       Install runtime + dev (test) dependencies"
	@echo "  saip      Install optional SAIP profile-generation dependencies"
	@echo "  test      Run the test suite"
	@echo "  cov       Run tests with coverage report"
	@echo "  run       Start the provisioning server (CONFIG_PATH to override config)"
	@echo "  init-db   Initialise the SQLite database"
	@echo "  profile   Generate a sample profile (FORMAT=v2|saip, OUT=file)"
	@echo "  clean     Remove caches and __pycache__"

install:
	$(PY) -m pip install -r requirements.txt

dev:
	$(PY) -m pip install -r requirements.txt -r requirements-dev.txt

saip:
	$(PY) -m pip install -r requirements-saip.txt

test:
	$(PY) -m pytest tests/ -q

cov:
	$(PY) -m pytest tests/ -q --cov=server --cov-report=term-missing

run:
	$(PY) -m server.app

init-db:
	$(PY) scripts/init_db.py

FORMAT ?= v2
OUT ?= profile.out
profile:
	$(PY) scripts/make_profile.py --format $(FORMAT) --out $(OUT)

clean:
	find . -type d -name __pycache__ -not -path './venv/*' -exec rm -rf {} + 2>/dev/null || true
	rm -rf .pytest_cache
