#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

export PYBUILD_NAME=xarray
PY3VERS:= $(shell py3versions -s)

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

override_dh_auto_clean:
	dh_auto_clean
ifeq (,$(findstring nodoc,$(DEB_BUILD_PROFILES)))
	$(MAKE) -C doc clean
endif

override_dh_auto_install: $(PYTHON3:%=install-python%)
	dh_auto_install
	find debian/python3-xarray -name '*.idx' -exec chmod -x {} \;

override_dh_auto_build:
	http_proxy=127.0.0.1:9 https_proxy=127.0.0.1:9 dh_auto_build
ifeq (,$(findstring nodoc,$(DEB_BUILD_PROFILES)))
	PYTHONPATH=$(CURDIR) $(MAKE) -C doc html
endif

# No dask for python2, so skip
override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	for p in $(PY3VERS); do \
		PY3VERNUM=`echo $$p | sed -e 's/python//' `; \
		pybuild --test --test-pytest -i $$p -p $$PY3VERNUM  ;  \
		done
endif

override_dh_sphinxdoc:
	dh_sphinxdoc --exclude=MathJax.js
	mv debian/python-xarray-doc/usr/share/doc/python-xarray/html debian/python-xarray-doc/usr/share/doc/python-xarray-doc
	rmdir debian/python-xarray-doc/usr/share/doc/python-xarray
