#!/usr/bin/make -f

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

include /usr/share/dpkg/default.mk

export PYBUILD_NAME=intake

# for hardening you might like to uncomment this:
# export DEB_BUILD_MAINT_OPTIONS=hardening=+all

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

override_dh_auto_build: export http_proxy=127.0.0.1:9
override_dh_auto_build: export https_proxy=127.0.0.1:9
override_dh_auto_build:
	dh_auto_build
	PYTHONPATH=. python3 -m sphinx -N -bhtml docs/source/ build/html/ # HTML generator
	PYTHONPATH=. python3 -m sphinx -N -bman docs/source/ build/man/ # Manpage generator

override_dh_install:
	dh_install

	# For some reason, not all data is movable via install or dh_install, so
	# just force copy (and overwrite if needed) for pytest to actually work
	set -e \
	; for py in `py3versions -sv` \
	; do builddir=".pybuild/cpython3_$${py}_$(PYBUILD_NAME)/build" \
	;    cp -a intake/source/tests $${builddir}/intake/source \
	;    cp -a intake/catalog/tests $${builddir}/intake/catalog \
	;    cp -a intake/interface/tests $${builddir}/intake/interface \
	; done

	PYBUILD_SYSTEM=custom \
		       PYBUILD_TEST_ARGS='cd {build_dir}; PATH=$(CURDIR)/debian/{package}/usr/bin:$(CURDIR)/debian/{package}/usr/lib:$(CURDIR)/debian/{package}/build/intake:$$PATH {interpreter} -m pytest intake/auth/tests intake/cli/tests intake/container/tests intake/tests' \
		       dh_auto_test --buildsystem=pybuild

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	echo "Build time test is done in dh_install."
endif
