.PHONY: all
all: format lint type-check test

.PHONY: help
help:
	@echo
	@echo 'Commands:'
	@echo
	@echo '  make install               install package in current environment'
	@echo '  make install-dev           install package with development dependencies'
	@echo '  make test                  run tests with coverage report'
	@echo '  make test-verbose          run tests with verbose output'
	@echo '  make lint                  run all linters'
	@echo '  make format                run code formatters'
	@echo '  make type-check            run static type checker'
	@echo '  make pre-commit            run pre-commit hooks'
	@echo '  make pre-commit-install    install pre-commit hooks'
	@echo '  make build                 build distribution packages'
	@echo '  make clean                 remove build artifacts and cache files'
	@echo '  make docs                  build documentation'
	@echo '  make docs-serve            serve documentation locally'
	@echo

.PHONY: install
install:
	pip install -e .

.PHONY: install-dev
install-dev:
	pip install -e ".[dev,test,docs]"
	$(MAKE) pre-commit-install

.PHONY: test test-verbose
test:
	python -m pytest

test-verbose:
	python -m pytest -vv

.PHONY: test-coverage
test-coverage:
	python -m pytest --cov=sgn_manifold --cov-report=html --cov-report=term

.PHONY: lint
lint: lint-black lint-isort lint-flake8 lint-mypy

.PHONY: lint-black
lint-black:
	black --check src/sgn_manifold/ tests/

.PHONY: lint-isort
lint-isort:
	isort --check-only src/sgn_manifold/ tests/

.PHONY: lint-flake8
lint-flake8:
	flake8 src/sgn_manifold/ tests/

.PHONY: lint-mypy
lint-mypy:
	cd src && mypy sgn_manifold/

.PHONY: format
format: format-isort format-black

.PHONY: format-isort
format-isort:
	isort src/sgn_manifold/ tests/

.PHONY: format-black
format-black:
	black src/sgn_manifold/ tests/

.PHONY: type-check
type-check:
	cd src && mypy sgn_manifold/

.PHONY: pre-commit
pre-commit:
	pre-commit run --all-files

.PHONY: pre-commit-install
pre-commit-install:
	pre-commit install

.PHONY: build
build: clean
	python -m build

.PHONY: clean
clean:
	find . -type f -name '*.pyc' -delete
	find . -type d -name '__pycache__' -delete
	find . -type d -name '*.egg-info' -exec rm -rf {} +
	rm -rf build/ dist/ .mypy_cache/ .pytest_cache/ htmlcov/ .coverage coverage.xml
	rm -rf .ruff_cache/ .tox/

.PHONY: docs
docs:
	mkdocs build

.PHONY: docs-serve
docs-serve:
	mkdocs serve

.PHONY: requirements
requirements:
	pip-compile -o requirements.txt pyproject.toml
	pip-compile --extra dev -o requirements-dev.txt pyproject.toml