#! /usr/bin/make -f

# export DH_VERBOSE=1
# export DH_OPTIONS=-v
# export PYBUILD_VERBOSE=1
# set verbosity of nose tests if needed, by uncommenting the following
#TESTS_VERBOSITY=--verbosity=2

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

export PYBUILD_NAME=rdflib

# For the time being, don't install the /usr/bin scripts for Python2 (hack)
# Instead, we'll patch the scripts to add a shebang and put links into /usr/bin
export PYBUILD_INSTALL_ARGS_python2=--install-scripts=/tmp
export PYBUILD_AFTER_INSTALL_python2=rm -fr '{destdir}/tmp/'
# For the time being, don't install the /usr/bin scripts for Python3 (hack)
export PYBUILD_INSTALL_ARGS_python3=--install-scripts=/tmp
export PYBUILD_AFTER_INSTALL_python3=rm -fr '{destdir}/tmp/'


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

override_dh_auto_build:
ifneq "$(shell dh_listpackages | grep -- -doc)" ""
	python setup.py build_sphinx
endif

override_dh_sphinxdoc:
ifneq "$(shell dh_listpackages | grep -- -doc)" ""
	dh_sphinxdoc
endif
#override_dh_sphinxdoc:
#(test -d $(CURDIR)/debian/python-rdflib-doc && dh_sphinxdoc) || /bin/true

# Make sure pybuild doesn't prevent running tests that require network connections (test_conneg) by setting proxy env vars
override_dh_auto_test:
	#This is supposed to be working at least for Python 2, and runs 1352 tests (71 skipped):
	# PYBUILD_DISABLE_python3=test \
	# http_proxy= https_proxy= dh_auto_test --buildsystem=pybuild
	#But we can alternatively use upstream provided script, which runs 1415 tests (71 skipped):
	#In a pybuild-compatible way, it goes :
	PYBUILD_DISABLE_python3=test \
	PYBUILD_SYSTEM=custom \
        PYBUILD_TEST_ARGS="{interpreter} run_tests.py $(TESTS_VERBOSITY) --exclude=test_conneg" \
	dh_auto_test --buildsystem=pybuild
	#To be uncommented once tests pass for Python 3, and once python3-sparqlwrapper is in the archive (and a build-dep)
	# #Then for Python 3 :
	# PYBUILD_DISABLE_python2=test \
	# PYBUILD_SYSTEM=custom \
        # PYBUILD_TEST_ARGS="./run_tests_py3.sh" \
	# http_proxy= https_proxy= \
	# dh_auto_test --buildsystem=pybuild

override_dh_installexamples:
	dh_installexamples -X.pyc

# The deps guessing seems not so perfect (SPARQLWrapper not needed everywhere, IMHO), so better do it manually
# The --no-shebang-rewrite is needed so that dh_python2 won't try to touch shebangs for the shell scripts (see #732308)
override_dh_python2:
	dh_python2 --no-guessing-deps --no-shebang-rewrite

override_dh_python3:
	dh_python3 --no-guessing-deps
