#!/usr/bin/make -f


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

export OSLO_PACKAGE_VERSION=$(VERSION)

PYTHON2=$(shell pyversions -vr)
PYTHON3=$(shell py3versions -vr)

%:
	dh $@ --with=python2,python3,sphinxdoc

override_dh_auto_build:
	set -e ; for pyvers in $(PYTHON2); do \
		python$$pyvers setup.py build; \
	done
	set -e ; for pyvers in $(PYTHON3); do \
		python$$pyvers setup.py build; \
	done

override_dh_auto_install:
	set -e ; for pyvers in $(PYTHON2); do \
		python$$pyvers setup.py install --install-layout=deb \
			--root $(CURDIR)/debian/python-stevedore; \
	done
	set -e ; for pyvers in $(PYTHON3); do \
		python$$pyvers setup.py install --install-layout=deb \
			--root $(CURDIR)/debian/python3-stevedore; \
	done

override_dh_clean:
	dh_clean -O--buildsystem=python_distutils
	rm -rf build

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	echo "===> Running tests"
	set -e ; for i in $(PYTHON2) $(PYTHON3) ; 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

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=$(CURDIR) sphinx-build -b html doc/source $(CURDIR)/debian/python-stevedore-doc/usr/share/doc/python-stevedore-doc/html
	dh_sphinxdoc -O--buildsystem=python_distutils
endif
