#!/usr/bin/make -f

UPSTREAM_GIT := https://github.com/pysal/momepy
include /usr/share/openstack-pkg-tools/pkgos.make

export SETUPTOOLS_SCM_PRETEND_VERSION=$(shell dpkg-parsechangelog -SVersion | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/~git.*//' -e 's/~bpo.*//' -e 's/~/.0/' -e 's/+dfsg1//' -e 's/+ds1//' | head -n 1)

TEST_EXPR := not test_Theil and not test_Gini and not test_Alignment
ifeq ($(DEB_HOST_ARCH),i386)
# Fails due to x87 excess precision, but the graph is indexed by floats so
# it's hard to fix the test properly.
TEST_EXPR += and not test_gdf_to_nx_angles
endif

export PYBUILD_NAME=monepy
export PYBUILD_TEST_ARGS=momepy/tests -v -k '$(TEST_EXPR)'

%:
	dh $@ --buildsystem=pybuild --with python3,sphinxdoc

override_dh_auto_clean:
	rm -rf build .stestr *.egg-info docs/generated
	rm -rf debian/python3-monepy
	find . -iname '*.pyc' -delete
	for i in $$(find . -type d -iname __pycache__) ; do rm -rf $$i ; done
	dh_auto_clean

override_dh_sphinxdoc:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. python3 -m sphinx -b html docs debian/python-momepy-doc/usr/share/doc/python-momepy-doc/html
	dh_sphinxdoc
endif

# Not sure why, but this package doesn't get installed automatically... :/
# Let's get it in manually.
override_dh_auto_install:
	dh_auto_install
	mkdir -p $(CURDIR)/debian/python3-momepy/usr/lib/python3/dist-packages
	cp -axuf .pybuild/cpython3_`py3versions -dv`_monepy/build/momepy* $(CURDIR)/debian/python3-momepy/usr/lib/python3/dist-packages
