#!/usr/bin/make -f

# For DEB_HOST_ARCH
include /usr/share/dpkg/architecture.mk

export PYBUILD_NAME=imbalanced-learn

# TBD: Why is this here?
ifeq ($(DEB_HOST_ARCH), i386)
	DEB_BUILD_OPTIONS += nocheck
endif

EXCLUDE_TESTS = not test_rusboost

# Bus errors triggered by scikit-learn
ifeq ($(DEB_HOST_ARCH), armhf)
	EXCLUDE_TESTS += and not test_common
endif

# This test is flaky, skip it for now
export PYBUILD_BEFORE_TEST=cd {build_dir}
export PYBUILD_TEST_ARGS=--import-mode=importlib -k "$(EXCLUDE_TESTS)" imblearn/tests/

%:
	dh $@ --buildsystem=pybuild

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# link to examples ... does not work
	# set -x && find .pybuild -name build -type d -exec ln -s $(CURDIR)/examples \{\} \;
	# set -x && find .pybuild -name build -type d -exec ln -s $(CURDIR)/imblearn/tests \{\}/imblearn \;
	# dh_auto_test
	set -e; for builddir in $(wildcard .pybuild/cpython3_*/build); do \
		python=$$(echo $$builddir | grep -oP 'cpython3_\K[0-9.]+'); \
		PYTHONPATH=$$builddir python$$python -m pytest \
			--import-mode=importlib \
			-k "$(EXCLUDE_TESTS)" \
			$(CURDIR)/imblearn/tests/; \
	done
endif
