.DEFAULT_GOAL := help
.PHONY: develop requirements build install lint-py lint-docs lint lints fix-py fix-docs fix format check-dist check-types checks check test tests coverage show-version patch minor major dist dist-build dist-py-wheel dist-py-sdist dist-check publish deep-clean clean help

develop:  ## install dependencies and build library
	uv pip install -e '.[develop]'

requirements:  ## install prerequisite Python build requirements
	uv pip install -r pyproject.toml --extra develop

build:  ## build the Python library
	python -m build -n

install:  ## install library
	uv pip install .

lint-py:  ## lint Python with ruff
	python -m ruff check python_template_cython
	python -m ruff format --check python_template_cython

lint-docs:  ## lint documentation
	python -m mdformat --check README.md docs/development.md $(wildcard docs/src)
	python -m codespell_lib README.md docs/development.md $(wildcard docs/src)

fix-py:  ## autoformat Python code
	python -m ruff check --fix python_template_cython
	python -m ruff format python_template_cython

fix-docs:  ## autoformat documentation
	python -m mdformat README.md docs/development.md $(wildcard docs/src)
	python -m codespell_lib --write README.md docs/development.md $(wildcard docs/src)

lint: lint-py lint-docs  ## run all linters
lints: lint
fix: fix-py fix-docs  ## run all autoformatters
format: fix

check-dist:  ## check python sdist and wheel with check-dist
	check-dist -v

check-types:  ## check Python types (advisory)
	ty check python_template_cython

checks: check-dist check-types  ## run distribution checks
check: checks

test:  ## run Python tests
	python -m pytest python_template_cython/tests

tests: test

coverage:  ## run tests with coverage
	python -m pytest python_template_cython/tests --cov=python_template_cython --cov-report term-missing --cov-report xml

show-version:  ## show current library version
	@bump-my-version show current_version

patch:  ## bump a patch version
	@bump-my-version bump patch

minor:  ## bump a minor version
	@bump-my-version bump minor

major:  ## bump a major version
	@bump-my-version bump major

dist-build:  ## build local Python distributions
	python -m build -w -s

dist-py-wheel:  ## build python wheel
	python -m cibuildwheel --output-dir dist

dist-py-sdist:  ## build python sdist
	python -m build --sdist -o dist

dist-check:  ## run python dist checker with twine
	python -m twine check dist/*

dist:  ## build and check local distributions
	$(MAKE) clean
	$(MAKE) dist-build
	$(MAKE) dist-check

publish: dist

deep-clean: ## clean everything from the repository
	git clean -fdx

clean:  ## remove distribution build output
	rm -rf build dist python_template_cython.egg-info

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

print-%:
	@echo '$*=$($*)'
