SHELL := bash
# PATH := venv/bin:$(PATH)

env ?= local
dc := docker-compose -f ${env}.yml
manage := python src/manage.py
pytest := python -m pytest

django_settings=kelvin.settings



check:
	${manage} check ${args}

install:
	pip install -r requirements.txt -r requirements.development.txt

sqlmigrate:
	${manage} sqlmigrate ${args}

makemigrations:
	${manage} makemigrations ${args}

showmigrations:
	${manage} showmigrations ${args}

manage:
	${manage} ${args}

migrate:
	${manage} migrate ${args}

runserver:
	${manage} runsslserver \
	    --certificate localdev/development.crt \
	    --key localdev/development.key 127.0.0.1:${if ${port},${port},8080} ${args}

runcelery:
	celery --workdir=./src -A kelvin worker -l info -E -B --scheduler django_celery_beat.schedulers:DatabaseScheduler

shell:
	${manage} shell ${args}

shell_plus:
	${manage} shell_plus ${args}

test:
	pytest ${if ${path},${path},./src} ${args}

test-integration:
	@make test path=./integration_tests ${args}

check-imports:
	isort --recursive --check-only --diff --skip-glob */migrations/* --skip-glob media --line-width 120 ${if ${path},${path},./src}

sort-imports:
	isort --recursive --atomic --skip-glob */migrations/* --skip-glob media  --line-width 120 ${if ${path},${path},./src}

starttvm:
	QLOUD_TVM_TOKEN=tvmtool-development-access-token tvmtool --port 8002 --verbose

build:
	VERSION=${VERSION} docker-compose build --no-cache api
	VERSION=${VERSION} docker-compose build --no-cache admin
	VERSION=${VERSION} docker-compose build --no-cache celeryworker
	VERSION=${VERSION} docker-compose build --no-cache celerybeat

push:
	VERSION=${VERSION} docker-compose push api
	VERSION=${VERSION} docker-compose push admin
	VERSION=${VERSION} docker-compose push celeryworker
	VERSION=${VERSION} docker-compose push celerybeat

ci:
	docker-compose -f ci.yml build ci && \
	docker-compose -f ci.yml run ci
