.PHONY: dev_env lint test test_unit test_integration clean unit_lint_job

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

env:
	python3.6 -m venv env
	env/bin/pip install -q -U pip setuptools wheel
	env/bin/pip install --use-feature=2020-resolver -q -I -r requirements.txt

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

lint: dev_env royalty_common tests setup.py
	env/bin/flake8 royalty_common/ tests/ setup.py

test: dev_env
	env/bin/python -m pytest tests/unit tests/integration

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

test_integration: clean
	cd tests/integration || exit 1
	rm -rf env
	python3.6 -m venv env
	env/bin/pip install -q -U pip setuptools wheel
	env/bin/pip install -q pytest==5.3.5
	env/bin/pip install --pre -q -I -i https://pypi.theorchard.io/pypi/ royalty-common
	env/bin/python -m pytest .

unit_lint_job: clean lint test_unit
