.PHONY: clean dev_env env_integration \
	lint test test_unit test_integration \
	unit_lint_job

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

env:
	python3.11 -m venv env
	env/bin/pip install -q -U pip setuptools wheel
	env/bin/pip install -q -I -r requirements.txt

dev_env: env requirements-dev.txt
	if [ ! -f env/bin/py.test ]; then env/bin/pip install -q -I -r requirements-dev.txt; fi

env_integration:
	python3.11 -m venv tests/integration/env
	tests/integration/env/bin/pip install -q -U pip setuptools wheel
	tests/integration/env/bin/pip install -q -i https://pypi.theorchard.io/pypi/ common-apispec pytest

lint: dev_env
	mypy common_apispec tests
	ruff check common_apispec tests
	ruff format common_apispec tests --check

test: dev_env
	env/bin/python -m pytest \
		tests/unit tests/integration \
		-s \
		-vv \
		--cov common_apispec \
		--cov-report term-missing

test_unit: dev_env tests
	env/bin/python -m pytest tests/unit tests/integration \
	    --cov common_apispec tests/unit tests/integration \
		--cov-report xml \
		--junitxml=pyunit.xml

test_integration:
	tests/integration/env/bin/python -m pytest tests/integration

unit_lint_job: clean lint test_unit

integration_job: clean env_integration test_integration
