# Developer tasks for the iocloud SDK + CLI.
#
# Everything runs the tools straight out of the active virtualenv, so `pip` and
# `uv` users get the same targets. Start with `make dev`, then `make check`.

PYTHON ?= python3
PIP ?= $(PYTHON) -m pip

.DEFAULT_GOAL := help
.PHONY: help install dev dev-docs lint format typecheck test test-live check docs docs-serve build clean

help:  ## Show this help
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
		| awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-12s\033[0m %s\n", $$1, $$2}'

install:  ## Install the package (runtime only)
	$(PIP) install -e .

dev:  ## Install with the dev and tui extras — what CI installs
	$(PIP) install -e ".[dev,tui]"

dev-docs:  ## Install the extra needed by `make docs` / `make docs-serve`
	$(PIP) install -e ".[docs]"

lint:  ## Lint sources, tests and examples
	ruff check src tests examples

format:  ## Apply ruff's autofixes
	ruff check --fix src tests examples

typecheck:  ## Type-check the package
	mypy src/iocloud

test:  ## Run the offline suite (coverage gate included)
	pytest -q

test-live:  ## Run the read-only smoke tests against the real API (needs IOCLOUD_API_KEY)
	IOCLOUD_TEST_LIVE=1 pytest tests/live -q --no-cov

check: lint typecheck test  ## Everything CI runs

docs:  ## Build the documentation site into site/ (needs the docs extra)
	mkdocs build --strict

docs-serve:  ## Serve the documentation site at http://127.0.0.1:8000
	mkdocs serve

build:  ## Build the sdist and wheel into dist/
	$(PYTHON) -m build

clean:  ## Remove build, test and coverage artefacts
	rm -rf build dist site htmlcov .coverage .pytest_cache .mypy_cache .ruff_cache
	find . -name '__pycache__' -type d -prune -exec rm -rf {} +
	find . -name '*.egg-info' -type d -prune -exec rm -rf {} +
