# Add any tasks that are not dependent on files to the .PHONY list.
.PHONY: install_from_lock install_from_lock_include_dev lint test_unit test_unit_cov deploy

# # https://pipenv.pypa.io/en/latest/advanced/#using-pipenv-for-deployments
#
# pipenv install --ignore-pipfile is nearly equivalent to pipenv sync,
# but pipenv sync will never attempt to re-lock your dependencies as
# it is considered an atomic operation. pipenv install by default does
# attempt to re-lock unless using the --deploy flag.

# Install all dependencies (including dev). Don not update Pipfile.lock
install_from_lock_include_dev:
	pipenv --rm sync --dev --python 3.8

# Install all dependencies (dev is not included). Don not update Pipfile.lock
install_from_lock:
	pipenv --rm sync --python 3.8

lint:
	pipenv run flake8 .

test_unit:
	PIPENV_DONT_LOAD_ENV=1 pipenv run py.test feed_status/ tests/

test: test_unit

sync:
	pipenv sync --python 3.11 --dev -v

lock:
	pipenv lock --python 3.11 --dev -v

docker_login:
	aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 086679231553.dkr.ecr.us-east-1.amazonaws.com

docker_unit_lint:
	chmod -R go+rw build/
	docker compose up \
		--build \
		--exit-code-from unit-lint \
		--abort-on-container-exit \
		--remove-orphans \
		unit-lint

docker_run_prod:
	# build and start production like server
	docker compose up production --build

docker_run_dev:
	# build and start dev server
	docker compose up --build

test_unit_cov:
	PIPENV_DONT_LOAD_ENV=1 PYTHONDONTWRITEBYTECODE=1 pipenv run pytest tests \
			--cov feed_status tests/ \
			--cov-report xml \
			--cov-report xml:build/coverage.xml \
			--cov-report term \
			--junitxml=pyunit.xml

docker_unit_lint_clean:
	docker compose down --remove-orphans

streamlit-run-dev:
	MONTY_API_BASE_URL=http://localhost:5000 pipenv run python -m streamlit run feed_status/ui/app.py

streamlit-run-qa:
	MONTY_API_BASE_URL=https://qa-monty.theorchard.io pipenv run python -m streamlit run feed_status/ui/app.py

streamlit-run-prod:
	MONTY_API_BASE_URL=https://monty.theorchard.io pipenv run python -m streamlit run feed_status/ui/app.py
