#!/usr/bin/make -f

export PYBUILD_NAME=scikit-optimize

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

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	pytest
else
	@echo "Skipping tests as per DEB_BUILD_OPTIONS"
endif

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

	# Remove or replace privacy-breach URLs with local paths
	find -type f -name "*.html" -exec sed -i 's|https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js|/usr/share/nodejs/mathjax-full/components/src/tex-chtml/tex-chtml.js|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css|/usr/share/javascript/bootstrap/css/bootstrap.min.css|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://code.jquery.com/jquery-3.7.0.js|/usr/share/javascript/jquery/jquery.js|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://raw.githubusercontent.com/holgern/scikit-optimize/main/media/bo-objective.png|(URL removed)|g' {} +

	# Remove license file
	find -type f -name "LICENSE.txt" -delete

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