# karyab dev tasks. For the app, use the CLI: karyab --help
#   (pipx install karyab)
#
#   make dev           install dev+runtime deps + git hooks
#   make test          run tests
#   make lint          ruff check
#   make fmt           ruff format
#   make typecheck     mypy
#   make check         pre-commit run --all-files
#   make clean         remove build artefacts
#   make distclean     clean + remove .venv

PYTHON    ?= python3
VENV   := .venv
BIN    := $(VENV)/bin
PY     := $(BIN)/python
PIP    := $(BIN)/pip

.PHONY: help
help:
	@echo "# karyab dev tasks. For the app, use the CLI: karyab --help"
	@echo "#   (pipx install karyab)"
	@echo ""
	@echo "  make install      install runtime deps into .venv"
	@echo "  make dev          install dev+runtime deps + git hooks"
	@echo "  make test         run tests"
	@echo "  make lint         ruff check ."
	@echo "  make fmt          ruff format ."
	@echo "  make typecheck    mypy src"
	@echo "  make check        pre-commit run --all-files"
	@echo "  make clean        remove build artefacts"
	@echo "  make distclean    clean + remove .venv"

# --- venv / install -------------------------------------------------------

$(PY):
	$(PYTHON) -m venv $(VENV)
	$(PIP) install -q --upgrade pip

.PHONY: install
install: $(PY)
	$(PIP) install -q -e "."
	@echo "installed karyab into $(VENV)"

.PHONY: dev
dev: $(PY)
	$(PIP) install -q -e ".[dev]"
	$(BIN)/pre-commit install
	@echo "dev environment ready"

# --- dev quality ----------------------------------------------------------

.PHONY: test
test: dev
	$(BIN)/pytest

.PHONY: lint
lint: dev
	$(BIN)/ruff check .

.PHONY: fmt
fmt: dev
	$(BIN)/ruff format .

.PHONY: typecheck
typecheck: dev
	$(BIN)/mypy src

.PHONY: check
check: dev
	$(BIN)/pre-commit run --all-files

.PHONY: clean
clean:
	rm -rf build dist *.egg-info .pytest_cache .ruff_cache .mypy_cache
	find . -type d -name __pycache__ -prune -exec rm -rf {} +

.PHONY: distclean
distclean: clean
	rm -rf $(VENV)
