#!/usr/bin/make -f

export PYBUILD_NAME=fake-factory
export DOC_PKG_NAME=faker-doc
SPHINXOPTS := -N

%:
	dh $@ --buildsystem=pybuild

override_dh_clean:
	dh_clean
	rm -rf .mypy_cache

override_dh_installman:
	PYTHONPATH="." help2man -n "command to generate fake data" --no-info \
		--output=debian/faker.1 debian/faker/usr/bin/faker
	dh_installman

override_dh_auto_install:
	dh_auto_install
	# Move the python 3 script to the faker package
	mkdir -p debian/faker/usr/bin
	mv debian/python3-fake-factory/usr/bin/faker debian/faker/usr/bin/

# tests needs package installed.
# please help to fix it if can
# see https://github.com/joke2k/faker/issues/1969
override_dh_auto_test:

override_dh_sphinxdoc:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=`dirname $$(find .pybuild/ -type d -name "*$(PYBUILD_NAME)*dist-info" | head -n1)` \
	python3 -m sphinx -b html $(SPHINXOPTS) docs $(CURDIR)/debian/$(DOC_PKG_NAME)/usr/share/doc/$(DOC_PKG_NAME)/html
	dh_sphinxdoc
endif

execute_after_dh_auto_install:
	dh_auto_test
