.PHONY: install test style lint format check build docs docs-serve clean

## Setup ----------------------------------------------------------------

install:  ## Install with dev dependencies
	uv sync --dev

## Quality --------------------------------------------------------------

test:  ## Run tests
	uv run pytest tests/ -v

test-cov:  ## Run tests with coverage report
	uv run pytest tests/ --cov=knowledgespaces --cov-report=term-missing --cov-fail-under=95

style:  ## Check code style (ruff lint + format check)
	uv run ruff check knowledgespaces/ tests/
	uv run ruff format --check knowledgespaces/ tests/

lint:  ## Same as style (alias)
	$(MAKE) style

format:  ## Auto-fix style issues
	uv run ruff check --fix knowledgespaces/ tests/
	uv run ruff format knowledgespaces/ tests/

check:  ## Run all checks (style + tests)
	$(MAKE) style
	$(MAKE) test-cov

## Documentation ---------------------------------------------------------

docs:  ## Build documentation (HTML)
	uv run --extra docs sphinx-build -b html docs docs/_build/html

docs-serve:  ## Build and serve docs locally
	$(MAKE) docs
	python -m http.server -d docs/_build/html 8000

## Build ----------------------------------------------------------------

build:  ## Build sdist and wheel
	rm -rf dist/
	uv build

clean:  ## Remove build artifacts
	rm -rf dist/ build/ *.egg-info .pytest_cache .coverage .ruff_cache docs/_build
	find . -type d -name __pycache__ -not -path './_research/*' -exec rm -rf {} +

## Help -----------------------------------------------------------------

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

.DEFAULT_GOAL := help
