# Add any tasks that are not dependent on files in the .PHONY list
.PHONY: clean test test_cov lint pip_dev unit_lint

clean:
	rm -rf \
		env \
		build \
		dist \
		tests/integration/env \
		.coverage \
		.pytest_cache \
		.ruff_cache \
		.cache \
		coverage.xml \
		owslogger.egg-info \
		pyunit.xml
	find . | grep -E '__pycache__|\.pyc|\.pyo$\' | xargs rm -rf

env:
	python3.11 -m venv .venv
	.venv/bin/python -m pip install -q -U pip setuptools wheel

pip_dev: env
	.venv/bin/python -m pip install -q -r requirements-dev.txt

docker_up:
	docker compose up -d

docker_down:
	docker compose down --remove-orphans

docker_test:
	docker compose up \
		--exit-code-from lint-and-test \
		--abort-on-container-exit \
		--build lint-and-test

test: pip_dev
	.venv/bin/python -m pytest tests

test_cov: pip_dev
	.venv/bin/python -m pytest \
		tests \
		--cov owslogger \
		--cov-report term-missing

lint: pip_dev
	.venv/bin/ruff format --check
	.venv/bin/ruff check
	.venv/bin/mypy

fmt format: pip_dev
	.venv/bin/ruff format
	.venv/bin/ruff check --fix

unit_lint: clean lint
	.venv/bin/python -m pytest \
		tests/ \
		--cov owslogger \
		--cov-report xml \
		--junitxml=build/pyunit.xml
	mv coverage.xml build/coverage.xml
