#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

include /usr/share/dpkg/architecture.mk

DEB_VERSION := $(shell dpkg-parsechangelog -S Version)
DEB_NOEPOCH_VERSION := $(shell echo $(DEB_VERSION) | cut -d: -f2-)
DEB_UPSTREAM_VERSION := $(shell echo $(DEB_NOEPOCH_VERSION) | sed 's/-[^-]*$$//')
DEB_STRIPPED_UPSTREAM_VERSION = $(shell echo $(DEB_UPSTREAM_VERSION) | sed -e 's/[\.\+]dfsg.*$$//')

export PYBUILD_NAME=pymatgen-core

# prevent SCM trying to read version from git
export SETUPTOOLS_SCM_PRETEND_VERSION=$(DEB_STRIPPED_UPSTREAM_VERSION)


%:
	dh $@ --buildsystem=pybuild

execute_after_dh_auto_clean:
	rm -f src/pymatgen/optimization/fast_parser.c \
	  src/pymatgen/optimization/neighbors.c \
	  src/pymatgen/util/coord_cython.c

override_dh_auto_test:
	SKIP_TESTS=""; \
	list_initialised=0; \
	for t in $(SKIP_TEST_LIST); do \
	    if [ $${list_initialised} = 0 ]; then \
	        SKIP_TESTS=$$t; \
	        list_initialised=1; \
	    else \
	        SKIP_TESTS="$${SKIP_TESTS} or $$t"; \
	    fi; \
	done; \
	if [ "x$${SKIP_TESTS}" != "x" ]; then \
	    SKIP_TESTS="not ( $${SKIP_TESTS} )"; \
	    echo "skipping tests: $${SKIP_TESTS}"; \
	fi; \
	cp -r /usr/share/doc/pymatgen-core-test-files/examples/test-files $(CURDIR)/.pybuild/; \
	for py in `py3versions -sv`; do \
	  pybuilddir=`pybuild --pyver $$py --print build_dir | awk '{print $$3}'`; \
	  testdir=$(CURDIR)/.pybuild/test_python$$py; \
	  cp -a $$pybuilddir $$testdir; \
	  cp -a tests $$testdir; \
	  PMG_TEST_FILES_DIR=$(CURDIR)/.pybuild/test-files \
	    PYTHONPATH=$$testdir PATH=$$pybuilddir/../scripts:$$PATH \
	    python$$py -m pytest -v $(EXTRA_TEST_FLAGS) --maxprocesses=8 --import-mode=prepend --color=no -k "$${SKIP_TESTS}" $$testdir; \
	done

execute_after_dh_python3:
	dh_numpy3
