#!/usr/bin/make -f

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)
export SETUPTOOLS_SCM_PRETEND_VERSION=$(shell dpkg-parsechangelog -SVersion | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/~/.0/' -e 's/+dfsg1//' | head -n 1)

%:
	dh $@ --with python3,sphinxdoc

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_auto_test:
	echo "Do nothing..."

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

override_dh_auto_install:
	pkgos-dh_auto_install --no-py2 --in-tmp

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

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

override_dh_sphinxdoc:
ifeq (,$(findstring nodoc, $(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
