# Variables you might need to change in the first place
#
# This is probably the only section you'll need to change in this Makefile.
# Also, make sure you don't remove the `<variables/>' tag. Cause those marks
# are going to be used to update this file automatically.
#
# <variables>
PACKAGE=forbiddenfruit
CUSTOM_PIP_INDEX=
export FFRUIT_EXTENSION=true
# </variables>

all: unit functional integration

unit:
	@make run_test suite=unit

functional:
	@make run_test suite=functional

integration:
	@make run_test suite=integration

run_test:
	@if [ -d tests/$(suite) ]; then \
		echo "Running \033[0;32m$(suite)\033[0m test suite"; \
		make prepare; \
		pytest --cov=$(PACKAGE) -vv tests/$(suite) ; \
	fi

prepare: clean install_deps build_test_stub

install_deps:
	@if [ -z $$SKIP_DEPS ]; then \
		echo "Installing missing dependencies..."; \
		[ -e requirements.txt ] && pip install -r requirements.txt &> .build.log; \
		[ -e development.txt  ] && pip install -r development.txt  &> .build.log; \
	fi

build_test_stub:
	@python setup.py build
	@find ./build -name '*.so' -exec mv {} tests/unit \;

clean:
	@echo "Removing garbage..."
	@find . -name '*.pyc' -delete
	@find . -name '*.so' -delete
	@find . -name __pycache__ -delete
	@rm -rf .coverage *.egg-info *.log build dist MANIFEST

dist: clean
	@echo "Building source distribution and wheel..."
	@# FFRUIT_EXTENSION is emptied so the `ffruit' C test stub is not
	@# bundled into the released package -- it's only used by the tests.
	@FFRUIT_EXTENSION= python -m build

publish: dist
	@echo "Uploading to PyPI with twine..."
	@twine upload dist/*
