.PHONY: format lint type typecheck test coverage docs import-smoke example-smoke benchmark-smoke smoke wheel-smoke package-check check

PYTHON ?= python3
MYPY_TARGETS ?= src/pyblackwell
TEST_ARGS ?=

format:
	ruff format src tests examples

lint:
	ruff check src tests examples

type:
	mypy $(MYPY_TARGETS)

typecheck: type

test:
	$(PYTHON) -m pytest $(TEST_ARGS)

coverage:
	$(PYTHON) -m pytest --cov=pyblackwell --cov-report=term-missing

docs:
	mkdocs build --strict

import-smoke:
	$(PYTHON) -c "import approachability; import pyblackwell; assert pyblackwell.MatrixGame is approachability.MatrixGame"

example-smoke:
	PYTHONPATH=src $(PYTHON) -m pytest tests/test_imports_and_examples.py

benchmark-smoke:
	PYTHONPATH=src $(PYTHON) benchmarks/run_benchmarks.py --mode smoke --iterations 20

smoke: import-smoke example-smoke benchmark-smoke

package-check:
	rm -rf build dist
	$(PYTHON) -m build
	$(PYTHON) -m twine check --strict dist/*
	$(MAKE) wheel-smoke

wheel-smoke:
	@set -eu; \
	tmpdir="$$(mktemp -d)"; \
	trap 'rm -rf "$$tmpdir"' 0; \
	$(PYTHON) -m venv "$$tmpdir/venv"; \
	"$$tmpdir/venv/bin/python" -m pip install dist/*.whl; \
	PYTHONPATH= "$$tmpdir/venv/bin/python" -c "from importlib import metadata; import approachability; import pyblackwell; assert pyblackwell.MatrixGame is approachability.MatrixGame; assert pyblackwell.__version__ == metadata.version('pyblackwell')"

check: lint type import-smoke test docs example-smoke benchmark-smoke package-check
