#!/usr/bin/make -f

PYTHONS:=$(shell pyversions -vr)
PYTHON3S:=$(shell py3versions -vr)

include /usr/share/openstack-pkg-tools/pkgos.make
export OSLO_PACKAGE_VERSION=$(VERSION)

%:
	dh $@  --with python2,python3

override_dh_auto_install:
	set -e ; for pyvers in $(PYTHONS); do \
		python$$pyvers setup.py install --install-layout=deb \
			--root $(CURDIR)/debian/python-heatclient ; \
	done
	set -e && for pyvers in $(PYTHON3S); do \
		python$$pyvers setup.py install --install-layout=deb \
			--root $(CURDIR)/debian/python3-heatclient ; \
	done
	mv $(CURDIR)/debian/python-heatclient/usr/bin/heat $(CURDIR)/debian/python-heatclient/usr/bin/python2-heat
	mv $(CURDIR)/debian/python3-heatclient/usr/bin/heat $(CURDIR)/debian/python3-heatclient/usr/bin/python3-heat
	rm -f $(CURDIR)/debian/python*/usr/lib/python*/dist-packages/*.pth

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3

override_dh_auto_clean:
	dh_auto_clean
	rm -rf .testrepository build

override_dh_install:
	dh_install
	rm -rf $(CURDIR)/debian/python3-heatclient/usr/heatclient

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	set -e ; for i in $(PYTHONS) $(PYTHON3S) ; do \
		PYMAJOR=`echo $$i | cut -d'.' -f1` ; \
		echo "===> Testing with python$$i (python$$PYMAJOR)" ; \
		rm -rf .testrepository ; \
		testr-python$$PYMAJOR init ; \
		TEMP_REZ=`mktemp -t` && \
		PYTHONPATH=$(CURDIR) PYTHON=python$$i testr-python$$PYMAJOR run --subunit | tee $$TEMP_REZ | subunit2pyunit ; \
		cat $$TEMP_REZ | subunit-filter -s --no-passthrough | subunit-stats ; \
		rm -f $$TEMP_REZ ; \
		testr-python$$PYMAJOR slowest ; \
	done
endif
