#!/usr/bin/make -f
export DH_VERBOSE=1
#export DEB_BUILD_OPTIONS=nocheck
export PYBUILD_NAME=pyutilib

export PYBUILD_INSTALL_ARGS=--install-scripts=/usr/share/{package} # the scripts are prevalently benign

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

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	for pt in `find pyutilib -name tests -type d` ; do \
	    cp -a $${pt}/* $(shell pybuild --print build_dir --interpreter python3)/$${pt} ; \
	done
	# PYTHONPATH=$(shell pybuild --print build_dir --interpreter python3)
	dh_auto_test || true
endif

override_dh_auto_install:
	dh_auto_install
	find debian/*/usr/lib/python3*/dist-packages/$(PYBUILD_NAME)/component/loader/tests/eggsrc -name setup.py -exec sed -i '1s+#!.*python$$+#!/usr/bin/python3+' \{\} \;
	sed -i '1s+#!.*python$$+#!/usr/bin/python3+' debian/*/usr/lib/python3*/dist-packages/$(PYBUILD_NAME)/enum/tests/test_enum.py

override_dh_installexamples:
	dh_installexamples examples/*
	install -d debian/python3-pyutilib/usr/share/doc/python3-pyutilib/examples/workflow
	cp -av doc/workflow/examples/* debian/python3-pyutilib/usr/share/doc/python3-pyutilib/examples/workflow/

override_dh_fixperms:
	dh_fixperms
	find debian/*/usr -name "*.txt" -exec chmod -x \{\} \;
