.PHONY: help clean test test_cov fmt lint pip_dev examples
.DEFAULT_GOAL := help

help:
	@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

clean:  ## Clean environment
	rm -rf env .eggs build jwtauth.egg-info .cache .pytest_cache .mypy_cache .coverage coverage.xml
	find . | grep -E '__pycache__|\.pyc|\.pyo$\' | xargs rm -rf

env pip_dev:  ## Prepare environment
	poetry install --all-extras

test: pip_dev  ## Run tests
	poetry run pytest tests/ \
		--cov jwtauth \
		--cov-report xml \
		--cov-report term \
		--junitxml=pyunit.xml

test_cov: pip_dev  ## Run tests with coverage
	poetry run pytest tests/ \
		--cov jwtauth \
		--cov-report term-missing

lint: pip_dev  ## Run code linters
	poetry run mypy jwtauth tests
	poetry run ruff check jwtauth tests setup.py
	poetry run ruff format jwtauth tests setup.py --check --diff

fmt:  pip_dev ## Run code formatters
	poetry run ruff check jwtauth tests setup.py --fix
	poetry run ruff format jwtauth tests setup.py


examples:  ## Build and install the package, then run the example tests.
	@echo "Running the linter in examples/testing/"
	cd examples/testing/ && make clean
	cd examples/testing/ && make lint

	@echo "Running the formatter in examples/testing/"
	cd examples/testing/ && make fmt

	@echo "Running example integration tests in examples/testing/"
	cd examples/testing/ && make examples
