# Copyright (c) 2015 Fabian Barkhau <fabian.barkhau@gmail.com>
# License: MIT (see LICENSE file)


PYTHON_VERSION = 3
WHEEL_DIR = /tmp/wheelhouse
USE_WHEEL = --use-wheel --no-index --find-links=$(WHEEL_DIR)
PIP = env/bin/pip
PY = env/bin/python


help:
	@echo "Some usefull development shortcuts."
	@echo "  clean      Remove all generated files."
	@echo "  setup      Setup development environment."
	@echo "  shell      Open ipython from the development environment."
	@echo "  test       Run tests and analysis tools."
	@echo "  wheel      Build package wheel and save in '$(WHEEL_DIR)'."
	@echo "  wheels     Build dependencie wheels and save in '$(WHEEL_DIR)'."
	@echo "  publish    Build and upload package to pypi.python.org"


clean:
	rm -rf env
	rm -rf build
	rm -rf dist
	rm -rf *.egg
	rm -rf *.egg-info
	find | grep -i ".*__pycache__.*$$" | xargs -r -L1 rm -rf
	find | grep -i ".*\.pyc$$" | xargs -r -L1 rm


virtualenv: clean
	virtualenv -p /usr/bin/python$(PYTHON_VERSION) env
	$(PIP) install wheel


wheels: virtualenv
	$(PIP) wheel --wheel-dir=$(WHEEL_DIR) -r requirements.txt
	$(PIP) wheel --wheel-dir=$(WHEEL_DIR) -r test_requirements.txt
	$(PIP) wheel --wheel-dir=$(WHEEL_DIR) -r develop_requirements.txt


wheel: test
	$(PY) setup.py bdist_wheel
	mv dist/*.whl $(WHEEL_DIR)


setup: virtualenv
	$(PIP) install $(USE_WHEEL) -r requirements.txt
	$(PIP) install $(USE_WHEEL) -r test_requirements.txt
	$(PIP) install $(USE_WHEEL) -r develop_requirements.txt


shell: setup
	env/bin/ipython


test: setup
	$(PY) setup.py test


publish: test
	$(PY) setup.py register bdist_wheel upload


# import pudb; pu.db # set break point