APP=$(shell basename $(CURDIR))
PACKAGE=$(subst _,-,$(APP))
STAGE?=dev

VENV_NAME?=venv
VENV_ACTIVATE=. $(VENV_NAME)/bin/activate

PIP = $(VENV_NAME)/bin/pip3
PYTHON = $(VENV_NAME)/bin/python3
WHEELHOUSE ?= wheels
# Set AWS ECR address if your tools is going to be executed in a cloud
REGISTRY ?= $(APP)
REVISION ?= $(shell git rev-parse --short=8 HEAD)
VERSION ?= $(shell git rev-parse --abbrev-ref HEAD)
BUILDTIME = $(shell date -u +"%Y%m%d%H%M%S")

##    venv - create local virtual env (base.pip dependencies)
$(VENV_NAME)/bin/activate:
	python3 -m venv $(VENV_NAME)

$(VENV_NAME): $(VENV_NAME)/bin/activate
	@echo "Creating virtial environment"
	$(PIP) install -U pip
	$(PIP) install -r requirements/pip/base.pip


##    logs - read logs in realtime
.PHONY: logs
logs:
	@docker-compose logs -f


##    clean - delete trash files
.PHONY: clean
clean:
	@echo "Deleting unnecessary files"
	@rm -rf build/
	@rm -rf dist/
	@rm -rf ./$(WHEELHOUSE)/
	@rm -rf *.egg-info
	@rm -rf *.pyc
	@rm -rf .*_cache
	@rm -rf __pycache__/
	@find . -name '*.pyc' -delete
	@find . -name '__pycache__' -delete

## -
## Docker commands:

##   docker/login - login to AWS docker, aws configuration need to be set first
.PHONY: docker/login
docker/login:
	@echo "Docker login"
	$$(aws ecr get-login --no-include-email --region us-east-1)


## -
## help - this message
.PHONY: help
help: Makefile
	@echo "Application: ${APP}\n"
	@echo "Run command:\n  make <target>\n"
	@grep -E -h '^## .*' $(MAKEFILE_LIST) | sed -n 's/^##//p'  | column -t -s '-' |  sed -e 's/^/ /'
