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

clean: ## Clean autogenerated files
	rm -rf dist
	rm -rf build
	rm -rf .venv
	find . -type f -name "*.DS_Store" -ls -delete
	find . | grep -E "(__pycache__|\.pyc|\.pyo)" | xargs rm -rf
	find . | grep -E ".pytest_cache" | xargs rm -rf
	find . | grep -E ".ipynb_checkpoints" | xargs rm -rf
	find . | grep -E ".ruff_cache" | xargs rm -rf
	rm -f .coverage

install: ## Install this project to site-packages
	uv sync --reinstall

stubs: install ## Generate stub file.
	uv run pybind11-stubgen inputtino._core -o src/
	@sed -i 's/def _pybind11_conduit_v1_(\*args, \*\*kwargs):/def _pybind11_conduit_v1_(*args: typing.Any, **kwargs: typing.Any) -> typing.Any:/' src/inputtino/_core.pyi

type: ## Run type check
	uv run pyright src

test: ## Run tests
	uv run pytest -v --log-level INFO --cov -m "not practical"

test-full: ## Run full test
	uv run pytest -v --cov

CPP_FILES=$(shell find src -regex '.*\.\(cpp\|hpp\|cc\|cxx\)')
PYTHON_FILES=$(shell find src -regex '.*\.\(py\|pyi\)')
PYTHON_TEST_FILES=$(shell find tests -regex '.*\.\(py\|pyi\)')
lint: ## Run linter
	uv run ruff check . --fix
	cppcheck $(CPP_FILES)
	cpplint $(CPP_FILES)

format: ## Run formatter
	uv run docformatter $(PYTHON_FILES) $(PYTHON_TEST_FILES) --in-place --wrap-summaries=79 --wrap-descriptions=72
	uv run pyupgrade --py310-plus $(PYTHON_FILES) $(PYTHON_TEST_FILES) 
	uv run ruff format .
	clang-format --style=Google -i $(CPP_FILES)

run: format lint test type ## Run all workflow.

includes: ## Shows the include directories.
	@pybind11-config --includes | tr ' ' '\n' | grep -e '^-I' | sed 's/^-I//'
	@echo $(PWD)/../../include
