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

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

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

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

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

lint: dev_env
	env/bin/python -m flake8 abacus_common_data/ tests/ setup.py

local_install:
	python3.8 -m venv env
	env/bin/python setup.py install

generate_whl: dev_env
	env/bin/python setup.py bdist_wheel

generate_tar_gz: dev_env
	env/bin/python setup.py sdist

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

test_unit: dev_env
	env/bin/python -m pytest tests/unit/ \
		--cov abacus_common_data \
		--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
