#!/usr/bin/make -f

export PYBUILD_NAME=goodvibes

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

override_dh_auto_install:
	dh_auto_install

	# Remove executable in not-elf-or-script
	find debian/python3-goodvibes/usr/lib/python3.*/dist-packages/goodvibes/examples -type f -exec chmod -x {} +

	# Exclude the 'goodvibes' executable
	rm debian/python3-goodvibes/usr/bin/goodvibes
	rm -d debian/python3-goodvibes/usr/bin

execute_after_dh_auto_install:
	# Remove unknown-file-in-python-module-directory
	rm -f debian/python3-goodvibes/usr/lib/python3.*/dist-packages/GoodVibes_test.dat

override_dh_installdocs:
	https_proxy='127.0.0.1:9' http_proxy='127.0.0.1:9' sphinx-build -b html docs build/sphinx/html

	#Remove or replace privacy-breach URLs with local paths
	find -type f -name "*.html" -exec sed -i 's|https://anaconda.org/patonlab/goodvibes/badges/downloads.svg|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://anaconda.org/patonlab/goodvibes/badges/installer/conda.svg|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://travis-ci.org/|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://readthedocs.org/projects/goodvibespy/badge/|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://img.shields.io/badge/|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://badge.fury.io/py/goodvibes.svg|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://anaconda.org/conda-forge/goodvibes/badges/downloads.svg|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://anaconda.org/conda-forge/goodvibes/badges/license.svg|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://zenodo.org/badge/54848929.svg|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://github.com/patonlab/GoodVibes/blob/master/goodvibes.png|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://github.com/patonlab/GoodVibes/actions/workflows/tests.yml/badge.svg|(URL removed)|g' {} +

	dh_installdocs -ppython-goodvibes-doc --doc-main-package=python-goodvibes-doc build/sphinx/html
	dh_installdocs
