.PHONY: dev_env pip_lock_versions \
	build clean dev \
	lint test test_unit \
	unit_lint_job

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

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

pip_lock_versions: clean
	python3.11 -m venv env
	env/bin/python -m pip install -U pip setuptools wheel
	env/bin/python -m pip install -I -r requirements-to-freeze.txt
	echo "-i https://pypi.theorchard.io/pypi/" > requirements.txt
	env/bin/python -m pip freeze >> requirements.txt

build: env
	env/bin/python application.py

clean:
	find . | grep -vE "^\./env" | grep -E '__pycache__|\.cache|\.pyc|\.pyo$\' | xargs rm -rf
	rm -rf \
		env \
		.coverage \
		.pytest_cache \
		pyunit.xml \
		coverage.xml

dev: dev_env
	env/bin/python dev.py

lint: dev_env
	env/bin/python -m flake8 \
		reports \
		tests \
		dev.py \
		application.py

test: dev_env
	env/bin/python -m pytest -s \
		--cov-report \
		term-missing \
		--cov=reports \
		tests/

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

unit_lint_job: clean lint test_unit
