#!/usr/bin/make -f

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

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

# ptk/async_*.py files contain the "async def" syntax, causing a
# compilation error for versions << 3.5.
PYBUILD_TARGETS := $(addprefix override_dh_auto_,configure build test install)
.PHONY: $(PYBUILD_TARGETS)
$(PYBUILD_TARGETS): override_dh_auto_%:
	mv ptk/async_*.py debian
	pybuild --$* --name=ptk --pyver="`pyversions -vr`" $(PYBUILD_ARGS)
	mv debian/async_*.py ptk
	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:
	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:
  # Versions > 1.2.0 should leave no doc/html in the way anymore.
	rm -fr .pybuild doc/build html
	rm -f README.rst
	find . -name "*.pyc" -delete
