#! /usr/bin/make -f

# export DH_VERBOSE=1
# export DH_OPTIONS=-v
# export PYBUILD_VERBOSE=1

# uncomment to deactivate tests to make package generation quicker
#export PYBUILD_DISABLE_python2=test

export PYBUILD_TEST_ARGS=-k "not (test_sparql_service or test_dawg_data_sparql10 or test_dawg_data_sparql11 or testGuessFormatForParse or test_graph_http or test_sparqlstore or test_suite or test_graph_update or test_sparql_datetime)"

# test_sparql_datetime is due to isodate 0.6.1 not being in Debian yet

export PYBUILD_NAME=rdflib

# Install (only) those into the -tools package
export PYBUILD_AFTER_INSTALL_python3=rm -rf 'debian/python-rdflib-tools/usr/bin'; mv '{destdir}/usr/bin' 'debian/python-rdflib-tools/usr/'

# upstream requires more recent sphinx now, which we have in stock Debian.
# Dynamically enable nodoc profile if sphinx is too old to simplify backports
SPHINX_VER = $(shell dpkg --compare-versions `dpkg -l python3-sphinx | awk '/^ii/{print $$3;}'` ge 2.4 && echo new || echo old )
ifeq "$(SPHINX_VER)" "old"
    export DEB_BUILD_PROFILES += nodoc
endif

%:
ifneq "$(shell dh_listpackages | grep -- -doc)" ""
	dh $@ --with sphinxdoc --buildsystem=pybuild
else
	dh $@ --buildsystem=pybuild
endif

override_dh_auto_build:
ifneq "$(shell dh_listpackages | grep -- -doc)" ""
	sphinx-build docs build/sphinx/html
endif
	dh_auto_build

override_dh_sphinxdoc:
ifneq "$(shell dh_listpackages | grep -- -doc)" ""
	dh_sphinxdoc
endif

override_dh_installexamples:
	dh_installexamples -X.pyc

override_dh_python3:
	dh_python3 --recommends-section=sparql --recommends-section=html
