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

#export DH_VERBOSE=1

export PYBUILD_NAME=pastescript
export PYBUILD_TEST_ARGS=\
--ignore=tests/appsetup/testfiles/conftest.py \
--ignore=tests/appsetup/test_make_project.py \
--ignore=tests/test_command.py \
--ignore=tests/test_egg_finder.py \
--ignore=tests/test_template_introspect.py

include /usr/share/dpkg/pkg-info.mk

BUILD_DATE  = $(shell LC_ALL=C date -u "+%d %B %Y" -d "@$(SOURCE_DATE_EPOCH)")
SPHINXOPTS := -E -N -D html_last_updated_fmt="$(BUILD_DATE)"

%:
	dh $@ --buildsystem=pybuild

ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
override_dh_sphinxdoc:
	PYTHONPATH=. python3 -m sphinx -b html $(SPHINXOPTS) docs/ $(CURDIR)/debian/python-pastescript-doc/usr/share/doc/python-pastescript-doc/html
	dh_sphinxdoc -O--buildsystem=pybuild
endif

override_dh_auto_install:
	dh_auto_install
	mv debian/python3-pastescript/usr/bin/paster debian/python3-pastescript/usr/bin/paster3
	dh_bash-completion

override_dh_installchangelogs:
	dh_installchangelogs docs/news.txt

override_dh_auto_clean:
	# Work around LP: #2035337
	mv tests/fake_packages/FakePlugin.egg/FakePlugin.egg-info/ fakeplugin.back
	dh_auto_clean
	mv fakeplugin.back tests/fake_packages/FakePlugin.egg/FakePlugin.egg-info/

override_dh_auto_test:
	# Another work around, the tests are not successful if called within the
	# .pybuild folder. But this way we have at least some tests while build.
	PYBUILD_SYSTEM=custom PYBUILD_TEST_ARGS="PYTHONPATH=$(CURDIR) {interpreter} -m pytest -v $${PYBUILD_TEST_ARGS}" dh_auto_test
