.PHONY: clean dev_env run \
	test test_unit ci lint \
	pip_lock_versions \
	deploy_job unit_lint_job \
	sync_docker start_ows docker_down

ci: clean dev_env
	env/bin/python -m pytest tests/integration --junitxml=pyunit.xml

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

deploy_job: clean env
	chmod +x deploy.sh
	./deploy.sh

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

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

lint: dev_env
	env/bin/python -m flake8 \
		dev.py \
		handler.py \
		index.py \
		snapshot_contract \
		tests/

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

run: dev_env
	env/bin/python dev.py

start_ows: sync_docker
	docker-compose up -d snapshot-contract-mysql
	docker-compose up snapshot-contract-liquibase-runner
	docker-compose up -d snapshot-contract-royalties

docker_down:
	docker-compose down --remove-orphans

sync_docker:
	`aws ecr get-login --no-include-email --region us-east-1`
	docker-compose pull

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

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

unit_lint_job: clean lint test_unit

test_integration:
	exit 0
