.PHONY: help clean env pip_dev test_unit test_cov fmt lint

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 .cache .pytest_cache .mypy_cache pyunit.xml .coverage coverage.xml
	find . | grep -E '__pycache__|\.pyc|\.pyo$\' | xargs rm -rf
	poetry env remove --all 2>/dev/null || true

pip_dev:  ## Prepare environment
	PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring poetry install
	
test_unit: pip_dev  ## Run unit tests
	mkdir -p build
	poetry run pytest tests/unit/ \
		--cov soundrecording_utils \
		--cov-report xml:build/coverage.xml \
		--cov-report term \
		--junitxml=build/pyunit.xml

ci_test: pip_dev lint test_unit  ## Run linter and unit tests (for CI)

test_cov: pip_dev  ## Run unit and integration tests with coverage
	poetry run pytest tests/ \
		--cov soundrecording_utils \
		--cov-report term-missing

lint: pip_dev  ## Run code linters
	poetry run mypy soundrecording_utils tests
	poetry run flake8 soundrecording_utils tests
