#!/usr/bin/make -f

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

export PYBUILD_DISABLE=python3.12

# For testing, we need .egg-info so the entry points are available.
export PYBUILD_BEFORE_TEST=python{version} setup.py develop --install-dir {build_dir}
# Delete .egg-info and other files that were generated along with .egg-info
export PYBUILD_BEFORE_INSTALL=rm -rvf {build_dir}/q2-feature-table.egg-* {build_dir}/site.py \
	{build_dir}/.coverage* {build_dir}/easy-install.pth

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

#FIXME: Delaying true testing to autopkgtests since QIIME2 module cannot be registered
#       at build time.
override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_test -- -s custom --test-args="cd {build_dir}; py.test-3 --cov=q2_quality_control" || true
endif

execute_after_dh_install:
	rm -v $(CURDIR)/debian/*/usr/lib/python3*/dist-packages/run_decontam.R
	find debian -name q2-quality-control.egg-link -delete

override_dh_auto_clean:
	dh_auto_clean
	rm -rf __pycache__ q2_quality_control.egg-info .pytest_cache
