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

env:  ## Prepare environment
	python3.8 -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 .[flask,starlette,fastapi,django,dev]

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

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

lint:  ## Run code linters
	.venv/bin/black owslib/ tests/ setup.py --check
	.venv/bin/isort owslib/ tests/ setup.py --check
	.venv/bin/flake8 owslib/ tests/ setup.py
	.venv/bin/mypy owslib/ tests/

fmt:  ## Run code formatters
	.venv/bin/black owslib/ tests/ setup.py
	.venv/bin/isort owslib/ tests/ setup.py
