.PHONY: pip_dev dev lint test test_unit pip_test_integration test_integration clean clean_test_integration

BASE_AWS_REGION     = us-east-1
BASE_AWS_ACCOUNT_ID = 437795906767
BASE_ECR_REGISTRY   = $(BASE_AWS_ACCOUNT_ID).dkr.ecr.$(BASE_AWS_REGION).amazonaws.com

env pip_dev:
	python3 -m venv env
	env/bin/pip3 install --upgrade pip
	env/bin/pip3 install -r requirements.txt
	env/bin/pip3 install -r requirements-dev.txt

dev: env
	env/bin/python3 dev.py

lint: env
	env/bin/python3 -m flake8 charts/ stubs/ tests/

test: env
	env/bin/py.test tests/unit/

test_unit: env
	env/bin/py.test \
		--cov --cov-branch charts tests/unit/ \
		--cov-report xml \
		--junitxml=pyunit.xml

test_integration:
	env/bin/pytest tests/integration/

mypy:
# TODO: Fix other files and expand
	env/bin/mypy \
		charts/constants/dates.py \
		charts/constants/new_music_friday.py \
		charts/logic/dataloaders \
		charts/logic/cache_prime.py \
		charts/logic/new_music_friday_date.py \
		charts/logic/new_music_friday.py \
		charts/logic/permissions.py \
		charts/new_music_friday_handlers.py \
		charts/utils/dataloader.py \
		charts/utils/db/ \
		charts/utils/sql_format.py \
		charts/features.py \
		tests/unit/fixtures/ \
		tests/unit/logic/dataloaders \
		tests/unit/logic/test_cache_prime.py \
		tests/unit/logic/test_new_music_friday_date.py \
		tests/unit/logic/test_new_music_friday.py \
		tests/unit/test_new_music_friday_handlers.py \
		tests/unit/utils/test_dataloader.py \
		tests/unit/test_features.py \

clean:
	rm -rf env

test_integration_qa:
	Environment=qa make test_integration

# The build step for https://pipeline.theorchard.io/job/ows-charts-unit-lint
unit_lint_job: clean pip_dev lint test_unit mypy

# The build step for https://pipeline.theorchard.io/job/ows-charts-integration-tests
integration_job: pip_dev test_integration_qa

# --- Local dev utils ---

docker_dev_build:
#  ensure your key is present at ~/.ssh/snowflake/rsa_key.p8
#  ensure your .env contains SNOWFLAKE_PRIVATE_KEY_PATH=/root/.ssh/snowflake/rsa_key.p8 when building the image
	mkdir -p tmp
	cp ~/.ssh/snowflake/rsa_key.p8 tmp/
	docker build -t ows-charts .
	rm -rf tmp/

docker_dev_run:
	docker run -p 5000:5000 ows-charts

docker/login/base:
	@aws ecr get-login-password | \
			docker login --username AWS --password-stdin $(BASE_ECR_REGISTRY)

docker/up-redis: docker/login/base
	docker-compose up -d redis

docker/down:
	docker-compose down
