.PHONY: fail-if-no-virtualenv all install loaddata test lint black debug undebug

all: install migrate loaddata collectstatic

fail-if-no-virtualenv:
ifndef VIRTUAL_ENV # check for a virtualenv in development environment
ifndef PYENVPIPELINE_VIRTUALENV # check for jenkins pipeline virtualenv
$(error this makefile needs a virtualenv)
endif
endif

ifndef PIP_INDEX_URL
PIP_INDEX_URL=https://pypi.mandelblog.com/mandel/testing/+simple/
endif

ifndef EXTRAS
EXTRAS="[test]"
endif

install: fail-if-no-virtualenv
	PIP_INDEX_URL=${PIP_INDEX_URL} pip install --pre --editable .${EXTRAS} setuptools wheel --upgrade --upgrade-strategy=eager  --use-deprecated=legacy-resolver

migrate:
	manage.py migrate --no-input

loaddata:
	-manage.py loaddemodata

collectstatic:
	manage.py collectstatic --no-input --verbosity=0

lint: fail-if-no-virtualenv
	cat mandelstudio/ocyan.json |python3 -m json.tool 1>/dev/null
	pylint setup.py mandelstudio/

black:
	@echo "No formatter configured in template; add your preferred formatter here."

test: fail-if-no-virtualenv
	@coverage run --source='mandelstudio' `which manage.py` test
	@coverage report
	@coverage xml
	@coverage html

run: fail-if-no-virtualenv lint test migrate collectstatic
	manage.py runserver

debug: fail-if-no-virtualenv
	PIP_INDEX_URL=${PIP_INDEX_URL} pip install --pre ocyan.plugin.debug

undebug:
	PIP_INDEX_URL=${PIP_INDEX_URL} pip uninstall -y ocyan.plugin.debug

live:
	@echo "Did you update the version in setup.py?  [y/N]" && read ans && [ $$ans = y ]
	rm -fr dist
	rm -fr build*
	version --plugin=wheel --skip-tag
	devpi --index=projects/production upload  dist/*
