.PHONY: install all check test test-all-versions coverage clean 

install:
	uv sync --all-extras
	./scripts/install.py
	@echo "Verify installation:"
	@echo "  opencode --version"
	@echo "  opencode run -m opencode/big-pickle \"Say hello\""


# Default target
all: check test


# Run all checks (format, lint, type check)
check:
	@uv sync --extra dev
	@uv run black src/botassembly tests
	@uv run ruff check --select I --fix src/botassembly tests
	@uv run ruff check --fix src/botassembly tests
	@uv run ruff check src/botassembly tests
	@uv run mypy src/botassembly tests/
	@uv run flake8 --select=C90 --max-complexity=8 src/botassembly tests/
	@PYTHONPATH=src uv run lint-imports

# Testing
test:
	uv run pytest tests

# Run tests across multiple Python versions using uv (no tox required).
# Configure which versions via `PY_VERSIONS` or pass extra pytest args via `ARGS`.
# Examples:
#   make test-all-versions
#   make test-all-versions ARGS="-k unit -q"
#   PY_VERSIONS="3.12 3.13" make test-all-versions
PY_VERSIONS ?= 3.10 3.11 3.12 3.13 3.14
test-all-versions:
	@set -e; \
	for v in $(PY_VERSIONS); do \
	  echo "👟 Running tests on Python $$v"; \
	  uv run --isolated --python=$$v --extra dev pytest $${ARGS:-tests}; \
	done

coverage: ## Run coverage across the full test suite (replay/REPL only)
	uv run coverage erase
	uv run coverage run -m pytest tests/
	uv run coverage html
	uv run coverage xml
	uv run coverage report --fail-under=70

# Cleanup
clean:
	rm -rf build/
	rm -rf dist/
	rm -rf src/*.egg-info/
	rm -rf .coverage
	rm -rf htmlcov/
	rm -rf .pytest_cache/
	rm -rf .mypy_cache/
	rm -rf .ruff_cache/
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete

publish:
	@uv build
	@uvx twine upload -r pypi dist/*
