UNAME := $(shell uname)
POETRY := poetry run
DOCS := cd docs && $(POETRY) make clean

ifeq ($(UNAME), Linux)
	OPEN = xdg-open
endif
ifeq ($(UNAME), Darwin)
	OPEN = open
endif
ifeq ($(UNAME), Windows)
	OPEN = start
endif

.PHONY: help clean docs

clean: clean-build clean-pyc clean-test

clean-build:
	rm -fr build/
	rm -fr dist/
	rm -fr .eggs/
	find . -name '*.egg-info' -exec rm -fr {} +
	find . -name '*.egg' -exec rm -fr {} +

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-test:
	rm -fr .tox/
	rm -f .coverage
	rm -fr htmlcov/
	rm -fr .pytest_cache

install:
	poetry install

test:
	$(POETRY) pytest
	cd docs && $(POETRY) make doctest

test-coverage:
	$(POETRY) pytest --cov-config .coveragerc --cov-report term-missing --cov-report html --cov=mpai_cae_arp

format:
	$(POETRY) yapf --in-place --recursive ./mpai_cae_arp ./tests

lint:
	$(POETRY) pylint ./mpai_cae_arp ./tests

docs:
	$(DOCS) && $(POETRY) make html && $(OPEN) build/html/index.html
