arcadia_root := $(shell ya dump root)
params := $(wordlist 2,100,$(MAKECMDGOALS))
source_root := Y_PYTHON_SOURCE_ROOT=$(arcadia_root)
entry_point := Y_PYTHON_ENTRY_POINT=":main"
pytest_args := -m pytest -p no:warnings -svv


# Code style
check-isort:
	isort --recursive --check-only --diff ciao/

check-flake8:
	flake8 ciao/

check-style: check-flake8 check-isort

sort-imports:
	isort --recursive ciao/

mypy:
	MYPYPATH=$(arcadia_root) mypy -p ciao --show-traceback --disallow-incomplete-defs

cc: sort-imports check-style mypy


# Tests
test:
	ya make -tt --test-stdout

test-unit:
	ya make -tt --test-stdout ciao/tests/unit

test-functional:
	ya make -tt --test-stdout ciao/tests/functional

dev-unit:
	$(source_root) $(entry_point) ./ciao/tests/unit/mail-ciao-ciao-tests-unit $(pytest_args) $(if $(params),$(params),ciao/tests/unit)

dev-functional:
	$(source_root) $(entry_point) ./ciao/tests/functional/mail-ciao-ciao-tests-functional $(pytest_args) $(if $(params),$(params),ciao/tests/functional)


# Development
deps:
	ya make --checkout ciao && ya make --checkout ciao/tests

build_bin:
	ya make bin

build_docker:
		ya package --docker --docker-repository mail/ciao package/package.json

runserver:
	$(source_root) ./bin/bin runserver

l_runserver:
	./run_local.sh make runserver

wl_runserver:
	./run_local.sh -w make runserver

shell:
	$(source_root) ./bin/bin shell

l_shell:
	./run_local.sh make shell

tunnel:
	ssh -NR 8001:localhost:8001 dev


# Localization
update-po:
	find ciao -type f -name "*py" | xgettext --from-code utf-8 -f - -o messages.po
	msgmerge -F -U locale/ru/LC_MESSAGES/ciao.po messages.po

build-mo:
	msgfmt -o locale/ru/LC_MESSAGES/ciao.mo locale/ru/LC_MESSAGES/ciao.po
