#!/usr/bin/make -f
include /usr/share/dpkg/pkg-info.mk

export LANG=C.UTF-8

# Look at upstream Makefile to find examples of how to run the test suite.
export PYBUILD_TEST_ARGS=\
	--verbose \
	-k "not cleannet \
	    and not test_stdout.py \
	    and not test_interchange_binding_with_non_ipv4_address" \
	--config parsl/tests/configs/local_threads.py
# Note that test_stdout.py is skipped due to missing appropriate typeguards.
# Also, test_interchange_binding_with_non_ipv4_address is fragile depending on
# the content of /etc/hosts.

PKGDIR=$(CURDIR)/debian/python3-parsl

%:
	dh $@ --buildsystem=pybuild --with=sphinxdoc

execute_after_dh_auto_build:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	# Build Sphinx documentation.
	$(MAKE) -C docs/ html
	# Remove dynamically injected privacy breaches.
	find docs/_build/html/ -name '*.html' -exec \
		sed -i 's@<script crossorigin="anonymous" integrity="[^"]*" src="https://[^"]*/require.min.js">@<script crossorigin="anonymous" src="file:///usr/share/javascript/requirejs/require.min.js">@' '{}' ';'
endif

execute_after_dh_install:
	# Cleanup unknown files landing in python3 modules directory.
	rm -rvf $(PKGDIR)/usr/lib/python3*/dist-packages/interchange.log \
		$(PKGDIR)/usr/lib/python3*/dist-packages/output.txt \
		$(PKGDIR)/usr/lib/python3*/dist-packages/hello1.txt \
		$(PKGDIR)/usr/lib/python3*/dist-packages/interchange.log \
		$(PKGDIR)/usr/lib/python3*/dist-packages/output.txt \
		$(PKGDIR)/usr/lib/python3*/dist-packages/std.out \
		$(PKGDIR)/usr/lib/python3*/dist-packages/runinfo

override_dh_installman: export PYTHONPATH=$(CURDIR)
override_dh_installman:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	# FIXME: exec_parsl_function.py is broken: due to a 'result_file' not
	# defined.  This script is thus not shipped for the moment.
	rm -vf $(PKGDIR)/usr/bin/exec_parsl_function.py
	#help2man $(PKGDIR)/usr/bin/exec_parsl_function.py \
	#	--name "execute a parsl function pickled in a file" \
	#	--version-string="$(DEB_VERSION_UPSTREAM)" \
	#	--no-info \
	#> debian/exec_parsl_function.py.1
	help2man $(PKGDIR)/usr/bin/parsl-perf \
		--name "performance measurements of parsl configuration" \
		--version-string="$(DEB_VERSION_UPSTREAM)" \
		--no-info \
	> debian/parsl-perf.1
	help2man $(PKGDIR)/usr/bin/parsl-visualize \
		--name "run parsl web dashboard" \
		--version-string="$(DEB_VERSION_UPSTREAM)" \
		--no-info \
	> debian/parsl-visualize.1
	help2man $(PKGDIR)/usr/bin/process_worker_pool.py \
		--name "create a parsl process worker pool" \
		--version-string="$(DEB_VERSION_UPSTREAM)" \
		--no-info \
	> debian/process_worker_pool.py.1
	# Note that parsl_coprocess.py spawns a server even if passing --help
	# or --version arguments, making it unsuitable for use with help2man.
	# Similarly, parsl-globus-auth attempts to connect to an authentication
	# server for Globus no matter what.  These commands are manually
	# documented instead.
	dh_installman --language=C
endif

before-pybuild-autopkgtest:
	# Pull test items that are otherwise uncaught by pybuild-autodep8.
	mkdir -p ../../autopkgtest_tmp/build/parsl
	cp -r /usr/lib/python3/dist-packages/parsl/tests \
		../../autopkgtest_tmp/build/parsl
