PYTHON?=python -X dev

all: help

help: 			## Show this help
	@echo -e "Specify a command. The choices are:\n"
	@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[0;36m%-12s\033[m %s\n", $$1, $$2}'
	@echo ""
.PHONY: help

# {{{ linting

format: isort black pyproject rustfmt	## Run all formatting scripts
.PHONY: format

fmt: format
.PHONY: fmt

isort:									## Run ruff isort fixes over the source code
	ruff check --fix --select=I src tests
	ruff check --fix --select=RUF022 src tests
	@echo -e "\e[1;32mruff isort clean!\e[0m"
.PHONY: isort

black:									## Run ruff format over the source code
	ruff format src tests
	@echo -e "\e[1;32mruff format clean!\e[0m"
.PHONY: black

pyproject:								## Run pyproject-fmt over the configuration
	$(PYTHON) -m pyproject_fmt \
		--indent 4 --max-supported-python '3.13' \
		pyproject.toml
	@echo -e "\e[1;32mpyproject clean!\e[0m"
.PHONY: pyproject

rustfmt:								## Run rustfmt
	cargo fmt -- bindings/*.rs
	@echo -e "\e[1;32mrustfmt clean!\e[0m"
.PHONY: rustfmt

lint: ruff clippy mypy					## Run all linting scripts
.PHONY: lint

ruff:									## Run ruff checks over the source code
	ruff check src tests
	@echo -e "\e[1;32mruff lint clean!\e[0m"
.PHONY: ruff

mypy:									## Run mypy checks over the source code
	$(PYTHON) -m mypy src tests
	@echo -e "\e[1;32mmypy clean!\e[0m"
.PHONY: mypy

clippy:									## Run clippy lint checks
	cargo clippy --all-targets --all-features
	@echo -e "\e[1;32mclippy clean!\e[0m"
.PHONY: clippy

# }}}

# {{{ testing

REQUIREMENTS=\
	requirements-dev.txt \
	requirements.txt

requirements.in:
	@echo "# This file is autogenerated. Do not modify it!" > $@
	@$(PYTHON) -c \
		'import tomllib; \
		c = tomllib.load(open("python/pyproject.toml", "rb")); \
		print("\n".join(c["build-system"]["requires"]))' >> $@
.PHONY: requirements.in

requirements-dev.txt: requirements.in pyproject.toml
	uv pip compile --upgrade --universal --python-version '3.10' \
		--extra dev \
		-o $@ $^
.PHONY: requirements-dev.txt

requirements.txt: requirements.in pyproject.toml
	uv pip compile --upgrade --universal --python-version '3.10' \
		-o $@ $^
.PHONY: requirements.txt

pin: $(REQUIREMENTS)	## Pin dependencies versions to requirements.txt
	cargo update
.PHONY: pin

pip-install:			## Install pinned dependencies from requirements.txt
	$(PYTHON) -m pip install -r requirements-dev.txt
	$(PYTHON) -m pip install --verbose --no-build-isolation --editable .
.PHONY: pip-install

test:					## Run pytest tests
	$(PYTHON) -m pytest
.PHONY: pytest

# }}}

# {{{

clean:			## Remove various build artifacts
	rm -rf build dist
	rm -rf docs/_build
.PHONY: clean

purge: clean	## Remove various temporary files
	rm -rf .ruff_cache .pytest_cache .mypy_cache
.PHONY: purge

# }}}
