# Add any tasks that are not dependent on files in the .PHONY list
.PHONY: help clean env pip_dev test test_cov fmt lint
.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 .venv .eggs build audience_common.egg-info .cache .pytest_cache .mypy_cache .coverage coverage.xml
	find . | grep -E '__pycache__|\.pyc|\.pyo$\' | xargs rm -rf

env:  ## Prepare environment
	python3.10 -m venv .venv
	.venv/bin/python -m pip install -q -U pip setuptools wheel

pip_dev: env  ## Prepare dev environment
	.venv/bin/python -m pip install -e .[dev]

test: pip_dev  ## Run tests
	.venv/bin/python -m pytest tests/ \
		--cov audience_common \
		--cov-report xml \
		--cov-report term \
		--junitxml=pyunit.xml

test_cov: pip_dev  ## Run tests with coverage
	.venv/bin/python -m pytest tests/ \
		--cov audience_common \
		--cov-report term-missing

lint:  ## Run code linters
	.venv/bin/mypy audience_common tests
	.venv/bin/ruff check audience_common tests setup.py
	.venv/bin/ruff format audience_common tests setup.py --check

fmt: ## Run code formatters
	.venv/bin/ruff check audience_common tests setup.py --fix
	.venv/bin/ruff format audience_common tests setup.py

