#!/usr/bin/make -f
# -*- makefile -*-

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

export PYBUILD_NAME=flask-sqlalchemy

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

override_dh_sphinxdoc:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	#############################################################################
	# Pallets is using the Python packages pallets-sphinx-themes, sphinx-issues #
	# *and* flask_sqlalchemy to create the running setup for the sphinx run.    #
	# As we are building python3-flask-sqlalchemy right now the usual call for  #
	# sphinx would fail as no package meta information would be found found.    #
	# We also can't use the package build in debian/python3-flask-sqlalchemy    #
	# as the installation didn't is finished yet!                               #
	# So we must relay an the build folder from the wheel creation in           #
	# /build/package/.pybuild. We pick up the folder with the most recent       #
	# Python build, while introducing a new Python version into Debian the      #
	# package wheel build will happen for all available Python versions!        #
	# The meta information is then the same, and the meta information is the    #
	# sphinx build looking for.                                                 #
	#############################################################################
	PYTHONPATH=`dirname $$(find .pybuild/ -type d -name "Flask_SQLAlchemy*dist-info" | head -n1)` \
	    python3 -m sphinx -N -q -E -b html -N docs $(CURDIR)/debian/flask-sqlalchemy-doc/usr/share/doc/flask-sqlalchemy-doc/html
	dh_sphinxdoc
endif

override_dh_installdocs:
	find examples -type f -name ".gitignore" -exec rm {} \;
	dh_installdocs

override_dh_auto_test:
	dh_auto_test -- --system=custom --test-args="PYTHONPATH={build_dir} {interpreter} -m pytest -v"
