#!/usr/bin/make -f

export DH_VERBOSE = 1
export PYBUILD_NAME = heudiconv

# for paranoid
export  http_proxy=http://127.0.0.1:9/

# to please datalad and git
export EMAIL=debian@example.com
export GIT_AUTHOR_NAME="The Name"
export GIT_COMMITTER_NAME=$(GIT_AUTHOR_NAME)
export PYBUILD_BEFORE_TEST := cp -a heudiconv/tests {build_dir}/heudiconv/

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

override_dh_auto_install:
	dh_auto_install
	mkdir -p build
	PYTHONPATH=$$(/bin/ls -d ./debian/heudiconv/usr/lib/python*/*-packages | head -n 1) \
	help2man -n 'DICOM converter for organizing brain imaging data into structured directory layouts' \
		-N --no-discard-stderr \
        "python3 -W ignore ./debian/heudiconv/usr/bin/heudiconv" >| build/heudiconv.1
	find debian -iname *.pyc -delete
	# https://github.com/nipy/heudiconv/issues/399
	rm -rf debian/heudiconv/usr/lib/python*/*-packages/Research
	find debian -name __pycache__ | xargs rm -rf


override_dh_clean:
	dh_clean
	# Ahhhhhhh!
	rm -rf .pybuild build .pytest_cache/
	-rm -rf heudiconv.egg-info/
