# Development tasks for the tensicai SDK. Everything runs through uv.
#
#   make install     create/update .venv with the dev extras
#   make check       lint + typecheck + test (what CI runs)
#   make test-all    run the test-suite on every supported Python version

UV ?= uv
PYTHON_VERSIONS ?= 3.10 3.11 3.12 3.13 3.14

.PHONY: help install lint format typecheck test test-all build check clean publish-test

help:
	@echo "install       uv sync --extra dev"
	@echo "lint          ruff check + ruff format --check"
	@echo "format        ruff format + ruff check --fix"
	@echo "typecheck     mypy src examples (strict)"
	@echo "test          pytest on the current interpreter"
	@echo "test-all      pytest on Python $(PYTHON_VERSIONS)"
	@echo "build         uv build + twine check"
	@echo "check         lint + typecheck + test"
	@echo "clean         remove build artefacts and caches"
	@echo "publish-test  upload dist/* to TestPyPI (twine)"

install:
	$(UV) sync --extra dev

lint:
	$(UV) run ruff check src tests examples
	$(UV) run ruff format --check src tests examples

format:
	$(UV) run ruff format src tests examples
	$(UV) run ruff check --fix src tests examples

typecheck:
	$(UV) run mypy src examples

test:
	$(UV) run pytest -q

test-all:
	@for v in $(PYTHON_VERSIONS); do \
		echo "=== Python $$v ==="; \
		$(UV) run --python $$v --isolated --extra dev pytest -q || exit 1; \
	done

build: clean
	$(UV) build
	$(UV) run twine check dist/*

check: lint typecheck test

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

# Rehearse a release against TestPyPI. Needs a TestPyPI API token:
#   TWINE_USERNAME=__token__ TWINE_PASSWORD=pypi-... make publish-test
publish-test: build
	$(UV) run twine upload --repository-url https://test.pypi.org/legacy/ dist/*
