# =============================================================================
# isarpy – Makefile
# Requires: uv (https://docs.astral.sh/uv/)
# Usage: make <target>
# =============================================================================

.DEFAULT_GOAL := install
.PHONY: install sync lock upgrade build publish test lint fmt fmt-check check pre-commit clean

# =============================================================================
# environment
# =============================================================================
install:                       ## Create .venv and install all deps (first-time setup)
	uv sync --all-extras

sync:                          ## Sync .venv with the current lock file (fast)
	uv sync

lock:                          ## Resolve deps and write/update uv.lock (no install)
	uv lock

upgrade:                       ## Upgrade all packages to latest allowed versions
	uv lock --upgrade
	uv sync

# =============================================================================
# build & publish
# =============================================================================
build:                         ## Build wheel + sdist into dist/
	uv build

publish:                       ## Publish to PyPI (requires PYPI_TOKEN or trusted pub)
	uv publish

publish-test:                  ## Publish to TestPyPI for a dry-run
	uv publish --index testpypi

# =============================================================================
# quality
# =============================================================================
test:                          ## Run the full pytest suite with coverage
	uv run pytest

test-fast:                     ## Run tests without coverage (quicker feedback)
	uv run pytest --no-cov

lint:                          ## Lint src/ and tests/ with ruff
	uv run ruff check src tests

fmt:                           ## Auto-format src/ and tests/ with ruff
	uv run ruff format src tests

fmt-check:                     ## Check formatting without modifying files
	uv run ruff format --check src tests

check: lint fmt-check test     ## Run lint + format-check + tests (mirrors CI)

pre-commit:                    ## Auto-fix style, then run every CI check locally
	@printf "\n[1/4] Auto-formatting (ruff format)...\n"
	uv run ruff format src tests
	@printf "\n[2/4] Lint check (ruff check)...\n"
	uv run ruff check src tests
	@printf "\n[3/4] Format check (ruff format --check)...\n"
	uv run ruff format --check src tests
	@printf "\n[4/4] Tests (pytest)...\n"
	uv run pytest
	@printf "\n All checks passed, ready to commit!\n\n"

# =============================================================================
# utils
# =============================================================================
clean:                         ## Remove build artefacts and cache dirs
	rm -rf dist/ .pytest_cache/ .ruff_cache/ htmlcov/ .coverage coverage.xml
	find . -type d -name "__pycache__" -exec rm -rf {} +
	find . -type d -name "*.egg-info"  -exec rm -rf {} +
