#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

export PYBUILD_TEST_ARGS=codespell_lib
ifeq ($(PYBUILD_AUTOPKGTEST),)
# During the build, we may be running as root, in which case a mode-0 test
# file will still be readable.
PYBUILD_TEST_ARGS += \
	--deselect codespell_lib/tests/test_basic.py::test_permission_error
# These tests expect to be able to run the codespell executable, which isn't
# installed during the build.
PYBUILD_TEST_ARGS += \
	--deselect codespell_lib/tests/test_basic.py::test_args_from_file \
	--deselect codespell_lib/tests/test_basic.py::test_command \
	--deselect codespell_lib/tests/test_basic.py::test_stdin
endif
export PYBUILD_AFTER_TEST=find {dir} -name junit-results.xml -delete

%:
	dh $@ --buildsystem=pybuild

execute_before_dh_installman:
	sed "s,PYTHONPATH=.,PYTHONPATH=`ls -d ./debian/codespell/usr/lib/python3*/dist-packages/`," < Makefile > tmp.mk
	PATH=$(PATH):$(CURDIR)/debian/codespell/usr/bin \
		$(MAKE) -f tmp.mk codespell.1
	rm -f tmp.mk
