.PHONY: help clean clean-build clean-pyc clean-translations lint test test-all coverage release release-sign dist install develop babel-extract babel-update babel-compile

PYTHON?=python3.8
PIP?=pip3
FIND?=find

help:
	@echo "fogstone"
	@echo
	@echo "clean - remove all build, test, coverage, frontend and Python artifacts"
	@echo "clean-build - remove build artifacts"
	@echo "clean-pyc - remove Python file artifacts"
	@echo "clean-translations - remove gettext *.mo files"
	@echo "lint - check style with pylint"
	@echo "test - run tests quickly with the default Python with pytest"
	@echo "test-all - run tests on every Python version with tox"
	@echo "coverage - check code coverage quickly with the default Python and pytest"
	@echo "release - package and upload a release"
	@echo "release-sign - package and upload a release with PGP sign"
	@echo "dist - package"
	@echo "install - install the package to the active Python's site-packages"
	@echo "develop - install the package for development as editable"
	@echo "babel-extract - create messages.pot translation template"
	@echo "babel-update - update .po translation files"
	@echo "babel-compile - compile .po translation files to .mo"

clean: clean-build clean-pyc clean-translations

clean-build:
	rm -fr build/
	rm -fr dist/
	rm -fr .eggs/
	rm -fr .tox/
	rm -fr *.egg-info
	rm -fr *.egg

clean-pyc:
	$(FIND) . -name '*.pyc' -exec rm -f {} +
	$(FIND) . -name '*.pyo' -exec rm -f {} +
	$(FIND) . -name '*~' -exec rm -f {} +
	$(FIND) . -name '__pycache__' -exec rm -fr {} +

clean-translations:
	rm -f fogstone/translations/*/LC_MESSAGES/*.mo

test:
	pybabel compile -d fogstone/translations
	$(PYTHON) setup.py test

test-all:
	pybabel compile -d fogstone/translations
	tox

coverage:
	$(PIP) install -r test-requirements.txt
	py.test --cov=fogstone --cov-report=html --cov-branch tests
	ls -lh htmlcov/index.html

release: clean
	$(PYTHON) setup.py sdist upload
	pybabel compile -d fogstone/translations
	$(PYTHON) setup.py bdist_wheel upload

release-sign: clean
	$(PYTHON) setup.py sdist upload --sign
	pybabel compile -d fogstone/translations
	$(PYTHON) setup.py bdist_wheel upload --sign

dist: clean
	$(PYTHON) setup.py sdist
	pybabel compile -d fogstone/translations
	$(PYTHON) setup.py bdist_wheel
	ls -lh dist

install: clean
	$(PYTHON) setup.py install

develop:
	$(PIP) install -r requirements.txt
	$(PYTHON) setup.py develop
	pybabel compile -d fogstone/translations

babel-extract:
	pybabel extract \
		-F babel.cfg \
		-k lazy_gettext \
		-o messages.pot \
		--project fogstone \
		fogstone

babel-update: babel-extract
	pybabel update -l ru -i messages.pot -d fogstone/translations

babel-compile:
	pybabel compile -l ru  -d fogstone/translations
