#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
# export DH_VERBOSE = 1

export HOME=$(CURDIR)/fakehome
export PYBUILD_NAME=snakemake
export PYBUILD_DESTDIR_python3=debian/snakemake
export PYBUILD_BEFORE_TEST_python3=chmod +x {dir}/bin/snakemake; cp -r {dir}/bin {dir}/tests {build_dir}
export PYBUILD_TEST_ARGS=python{version} -m pytest tests/test*.py -n auto -k 'not report and not ancient and not test_script and not default_remote and not issue635 and not convert_to_cwl and not issue1083 and not issue1092 and not issue1093 and not test_remote and not test_default_resources and not test_tibanna and not test_github_issue78 and not test_output_file_cache_remote and not test_env_modules'

# test_report
# test_ancient
# test_script requires conda; manually disabling conda show the need for the binary 'julia'
# test_default_remote requires network access
# test_issue634 requires conda, but passes when conda is turned off manually
# test_convert_to_cwl tries to build a singularity format software image from docker://quay.io/snakemake/snakemake:v5.5.4
# test_issue1083 tries to build a singularity format software image from docker://bash
# test_issue1093 fails due to conda usage; commenting that out and installing bwa produces a different ordering than desired
# test_default_resources and test_remote needs moto to be packaged https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=777089
# test_env_modules relies on "module load" which is not packaged for Debian

export PYBUILD_AFTER_TEST_python3=rm -fr {build_dir}/bin {build_dir}/tests {dir}/tests/test_filegraph/.snakemake/

export PATH:=$(shell pybuild --print build_dir --interpreter python3 --name $(PYBUILD_NAME))/bin:$(PATH)

# Force the use of python3's sphinx-build.
export SPHINXBUILD=/usr/share/sphinx/scripts/python3/sphinx-build

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

override_dh_auto_build:
	dh_auto_build
	PATH=$(shell pybuild --print build_dir --interpreter python3)/bin:$(PATH) \
	PYTHONPATH=$(shell pybuild --print build_dir --interpreter python3) \
		python3 setup.py build_sphinx

override_dh_auto_install:
	dh_auto_install
	find . -name '__pycache__' | xargs rm -Rf
	find . -name '*.pyc' | xargs rm -Rf
	find debian -name '.gitignore' | xargs rm -Rf

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	mkdir -p $(CURDIR)/fakehome
	PYBUILD_SYSTEM=custom dh_auto_test
endif
