#!/usr/bin/make -f

DH_VERBOSE := 1
export LC_ALL=C.UTF-8
export PYBUILD_TEST_PYTEST = 1

include /usr/share/dpkg/default.mk
VERSION_UPSTREAM=$(shell echo $(DEB_VERSION_UPSTREAM) | sed -e 's/\(20[0-9][0-9]\.[0-9]\+\)\..*/\1/')

debian/control: debian/control.in
	echo "# This file is autogenerated from control.in to update versioned dependencies" > $@
	sed -e"s/@DEB_VERSION_UPSTREAM@/$(VERSION_UPSTREAM)/g" $< >> $@

%:
	dh $@ --buildsystem=pybuild

override_dh_auto_install:
	dh_auto_install --destdir=debian/q2-sample-classifier
	find debian/q2-sample-classifier -type d -name __pycache__ -prune -exec rm -rf {} +

# Run the test suite at build time via pybuild (pytest).  Debian policy
# requires tests to work without network access; block it with a dead
# proxy so any accidental network attempt fails fast.
override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	env no_proxy="" http_proxy="http://127.0.0.1:9" \
	    https_proxy="http://127.0.0.1:9" ftp_proxy="http://127.0.0.1:9" \
	    dh_auto_test
endif

override_dh_auto_clean:
	dh_auto_clean
	rm -rf .pytest_cache build
	rm -f q2_sample_classifier.egg-info/PKG-INFO q2_sample_classifier.egg-info/SOURCES.txt q2_sample_classifier.egg-info/dependency_links.txt q2_sample_classifier.egg-info/entry_points.txt q2_sample_classifier.egg-info/not-zip-safe q2_sample_classifier.egg-info/top_level.txt
	find . -name __pycache__  | xargs -r rm -r

override_dh_usrlocal:
	# fails - no idea why
