#!/usr/bin/make -f

PYTHON3:=$(shell py3versions -r)
py3sdo=set -ex; $(foreach py, $(PYTHON3), $(py) $(1);)

UPSTREAM_GIT := https://github.com/Julian/jsonschema.git
include /usr/share/openstack-pkg-tools/pkgos.make

export PACKAGE_VERSION=$(shell dpkg-parsechangelog | grep Version: | cut -d' ' -f2 | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/~/.0/' | head -n 1)

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

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	set -e ; for i in 2.7 $(PYTHON3S) ; do \
		PYTHON=python$$i python$$i -m nose -v ; \
	done
endif

override_dh_auto_build:
	echo $$PACKAGE_VERSION  | sed s/\\./-/g >version.txt
	dh_auto_build
	$(call py3sdo, setup.py build)

override_dh_auto_install:
	pkgos-dh_auto_install

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

override_dh_auto_clean:
	echo $$PACKAGE_VERSION  | sed s/\\./-/g >version.txt
	#http_proxy=127.0.0.1:9 https_proxy=127.0.0.1:9 dh_auto_clean
	rm -rf build version.txt
	rm -rf __pycache__

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	http_proxy=127.0.0.1:9 https_proxy=127.0.0.1:9 HTTP_PROXY=127.0.0.1:9 HTTPS_PROXY=127.0.0.1:9 PYTHONPATH=$(CURDIR) PYTHON=python3 python3 -m sphinx $(SPHINXOPTS) -b html docs $(CURDIR)/debian/python-jsonschema-doc/usr/share/doc/python-jsonschema-doc/html
	dh_sphinxdoc
endif
