#########################################
# Python-opinionated makefile
#########################################

define default-help
# Invoke: 'make help'
endef
.PHONY: default
default: help


define build-help
# Build py2ecma python packages from project
endef
.PHONY: build
build:
	@echo " ## make build [BEGIN]"
	./scripts/build.sh
	@echo " ## make build [DONE]"


define docker-help
# Build docker image from Dockerfile
endef
.PHONY: docker
docker:
	@echo " ## make docker [BEGIN]"
	docker build -t py2ecma-dev --target py2ecma-dev  .
	docker build -t py2ecma-ci --target py2ecma-ci  .
	@echo " ## make docker [DONE]"


define clean-help
# Remove virtual python environment & build artifacts if applicable
endef
.PHONY: clean
clean:
	@echo " ## make clean [BEGIN]"
	rm -fr .venv || true
	rm -fr .dist || true
	@echo " ## make clean [DONE]"


define docs-help
# Build docs with makefile, outputs html as a directory.
endef
.PHONY: docs
docs:
	@echo " ## make docs [BEGIN]"
	$(MAKE) -C ./docs dirhtml
	@echo " ## make docs [DONE]"


define install-help
# Install development environment, install root as editable
endef
.PHONY: install
install:
	@echo " ## make install [BEGIN]"
	./scripts/install.sh
	@echo " ## make install [DONE]"


define install-ci-help
# Install packages for ci, dont't install project root
endef
.PHONY: install-ci
install-ci:
	@echo " ## make install [BEGIN]"
	./scripts/install_ci.sh
	@echo " ## make install [DONE]"


define install-minimal-help
# Install packages excluding development packages
endef
.PHONY: install-runtime
install-runtime:
	@echo " ## make install-runtime [BEGIN]"
	./scripts/install_runtime.sh
	@echo " ## make install-runtime [DONE]"


define format-help
# Run linters and auto formatters.
# This uses black and isort
endef
.PHONY: format
format:
	@echo " ## make format [BEGIN]"
	./scripts/format.sh
	@echo " ## make format [DONE]"


define verify-help
# Run linters and verify project integrity.
# This includes flake8, isort, black and mypy.
endef
.PHONY: verify
verify:
	@echo " ## make verify [BEGIN]"
	./scripts/verify.sh
	@echo " ## make verify [DONE]"


define run-help
# Run application, postfix with ARGS="..." for cli arguments.
# Such that ARGS="<--flags> <input_data>" for flags and input data.
# As an example: `make run ARGS="--help"`
endef
.PHONY: run
run:
	@echo " ## make run [BEGIN]"
	python src/py2ecma/main.py ${ARGS}
	
	@echo " ## make run [DONE]"




define tests-help
# Run testcases via pytest
endef
.PHONY: tests
tests:
	@echo " ## make test [BEGIN]"
	./scripts/tests.sh
	@echo " ## make test [DONE]"


define tests-cov-help
# Run tests via pytest producing a coverage report
endef
.PHONY: tests-cov
tests-cov:
	@echo " ## make test [BEGIN]"
	./scripts/tests-cov.sh
	@echo " ## make test [DONE]"


define deploy-help
# Deploy project with helm
endef
.PHONY: deploy
deploy:
	@echo " ## make deploy [BEGIN]"
	./scripts/deploy.sh	
	@echo " ## make deploy [DONE]"


define release-help
# Release python packages defined in pyproject.toml to package repository
# This command uses twine and will need to be authenticated with repository.
# Use the environment variables to specify authentication.
endef
.PHONY: release
release:
	@echo " ## make release [BEGIN]"
	twine upload dist/*
	@echo " ## make release [DONE]"


define help-help
# Print the description of every target
endef
.PHONY: help
help:
	@./.print_help.py


define help-verbose-help
# Print the verbose description of every target
endef
.PHONY: help-verbose
help-verbose:
	@./.print_help.py --verbose