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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

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

# tell pybuild which module to install into the packages
export PYBUILD_NAME=debian

%:
	dh $@ --with python3 --buildsystem pybuild

%.py: %.py.in debian/changelog
	sed -e 's/__CHANGELOG_VERSION__/$(DEB_VERSION)/' < $< > $@

override_dh_auto_build: lib/debian/_version.py
	dh_auto_build
	lib/debian/doc-debtags > README.debtags

override_dh_auto_clean:

override_dh_auto_test:

override_dh_auto_install:
	dh_auto_install
	# setuputils may produce different files for different versions of
	# python and dh_python3 will leave them behind.
	rm -rf $(CURDIR)/*/usr/lib/python3.*

dist: lib/debian/_version.py
	rm -f dist/python?debian-$(DEB_VERSION)*
	python3 setup.py sdist bdist_wheel bdist_egg
	echo "You can now: twine upload --sign dist/python?debian-$(DEB_VERSION)*"

apidoc:
	rm -f docs/api/*
	cd lib && sphinx-apidoc -e --private -H python-debian \
	  -o ../docs/api/ . \
	  deb822.py debian/tests/ debian_bundle/

doc: apidoc
	PYTHONPATH=$(CURDIR)/lib \
	  make -C docs/ SPHINXOPTS="-a -v -n" html

qa: lib/debian/_version.py
	@echo "Running both pylint and mypy"
	@echo "----------- pylint -----------"
	@pylint --rcfile .pylintrc $$(find lib/debian -name \*py | grep -v test | sort); \
	  pylinterr=$$?; \
	  echo "----------- mypy -----------"; \
	  mypy --strict lib; \
	  mypyerr=$$? ; \
	  [ $$pylinterr -eq 0 -a $$mypyerr -eq 0 ]

.PHONY: dist doc apidoc qa
