#!/usr/bin/make -f

# See https://wiki.debian.org/Python/LibraryStyleGuide.

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

PYBUILD_TARGETS := $(addprefix override_dh_auto_,configure build test install)
.PHONY: $(PYBUILD_TARGETS)
$(PYBUILD_TARGETS): override_dh_auto_%:
	pybuild --$* --name=ptk --pyver="`py3versions -vr`" $(PYBUILD_ARGS)

# README.rst and html are also mentioned in python-ptk-doc.doc*.
override_dh_auto_build: README.rst html
README.rst:
	$(MAKE) prepare
# Forbid internet access.
# Select Python3, able to parse async def in imported Python modules.
html:
	https_proxy=127.0.0.1:9 \
	PYTHONPATH=. http_proxy='127.0.0.1:9' $(MAKE) documentation \
	  SPHINXBUILD=/usr/share/sphinx/scripts/python3/sphinx-build

# Discover requires an explicit start-directory to find anything.
# Only run test_all.py, which skips twisted if it is not installed.
override_dh_auto_test: PYBUILD_ARGS := \
  "--test-args=--start-directory=tests --pattern=test_all.py"

# Avoid pybuild when cleaning, as it creates subdirectories.
.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	rm -fr .pybuild doc/build html
	find . -name '*.pyc' -delete
	rm -f README.rst

.PHONY: override_dh_installdocs
override_dh_installdocs:
	dh_installdocs --package=python-ptk-doc --doc-main-package=python3-ptk
	dh_installdocs --remaining-packages
