.DEFAULT_GOAL := all
sources = src tests

.PHONY: .uv  ## Check that uv is installed
.uv:
	@uv --version || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'

.PHONY: .pre-commit  ## Check that pre-commit is installed
.pre-commit:
	@pre-commit -V || echo 'Please install pre-commit: https://pre-commit.com/'

.PHONY: install  ## Install the package, dependencies, and pre-commit for local development
install: .uv .pre-commit
	uv sync --all-groups
	pre-commit install --install-hooks

.PHONY: format  ## Auto-format python source files
format: .uv
	uv run ruff format $(sources)
	uv run ruff check --fix $(sources)

.PHONY: lint  ## Lint python source files
lint: .uv
	uv run ruff format --check $(sources)
	uv run ruff check $(sources)

.PHONY: typecheck  ## Run ty type checking
typecheck: .uv
	uv run ty check $(sources)

.PHONY: test  ## Run all tests
test: .uv
	uv run pytest

.PHONY: all  ## Run format, lint, typecheck, and test
all: format lint typecheck test

.PHONY: clean  ## Clear local caches and build artifacts
clean:
	rm -rf .venv dist *.egg-info .pytest_cache .mypy_cache .ty_cache .ruff_cache

.PHONY: help  ## Display this message
help:
	@grep -E \
		'^.PHONY: .*?## .*$$' $(MAKEFILE_LIST) | \
		sort | \
		awk 'BEGIN {FS = ".PHONY: |## "}; {printf "\033[36m%-19s\033[0m %s\n", $$2, $$3}'
