#!/usr/bin/make -f

#export DH_VERBOSE=1

include /usr/share/openstack-pkg-tools/pkgos.make

%:
	dh $@ --buildsystem=python_distutils  --with python2,python3,systemd

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	# NOTE(coreycb) Skip Py3.7 tests until they run successfully upstream:
	# https://storyboard.openstack.org/#!/story/2003186
	# pkgos-dh_auto_test '^(?!heat_integrationtests)'
	echo "===> Running tests"
	set -ex ; for i in 2.7 3.6 ; do \
		PYMAJOR=`echo $$i | cut -d'.' -f1` ; \
		echo "===> Testing with python$$i (python$$PYMAJOR)" ; \
		rm -rf .stestr ; \
		TEMP_REZ=`mktemp -t` ; \
		PYTHONPATH=$(CURDIR) PYTHON=python$$i python$$PYMAJOR-stestr run --subunit '^(?!heat_integrationtests)' | tee $$TEMP_REZ | subunit2pyunit ; \
		cat $$TEMP_REZ | subunit-filter -s --no-passthrough | subunit-stats ; \
		rm -f $$TEMP_REZ ; \
		rm -rf .stestr ; \
	done
endif

override_dh_clean:
	dh_clean
	rm -rf doc/build
	find . -iname '*.pyc' -delete
	rm -f run_tests.err.log
	rm -rf pbr*.egg
	rm -f etc/heat/heat.conf
	rm -f debian/*.init debian/*.service debian/*.upstart

override_dh_auto_clean:
	dh_auto_clean

override_dh_auto_install:
	pkgos-dh_auto_install
	rm -rf $(CURDIR)/debian/python*-heat/usr/etc

override_dh_install:
	PYTHONPATH=$(CURDIR)/debian/python3-heat/usr/lib/python3/dist-packages \
		python3-oslo-config-generator --config-file=config-generator.conf \
		--output-file etc/heat/heat.conf
	dh_install

#override_dh_installman:
#	python setup.py build
#	make -C doc man
#	dh_installman
