#!/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 PYBUILD_NAME=custodian

PY3VER_DEF = $(shell py3versions -dv)

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

# don't delete test .orig files
override_dh_clean:
	dh_clean --exclude=tests/files

override_dh_auto_test:
	rm -rf .pybuild/tests
	cp -r tests .pybuild
	# pymatgen is needed for tests but
	# spglib is only available on the default python version
	CUSTODIAN_TEST_DIR=$(CURDIR)/.pybuild/tests  pybuild --test --test-pytest -p $(PY3VER_DEF) \
	    --test-args='-k "not (test_fileman_cpscf_nseg_error or test_gdm_neg_precon_error or test_OptFF or test_first_step)"'

execute_after_dh_auto_build-indep: export http_proxy=127.0.0.1:9
execute_after_dh_auto_build-indep: export https_proxy=127.0.0.1:9
execute_after_dh_auto_build-indep:
	PYTHONPATH=. python3 -m sphinx -N -bhtml \
	docs/ .pybuild/docs/html # HTML generator

execute_after_dh_installdocs:
	for f in `find debian/python-custodian-doc/usr/share/doc/python-custodian-doc/html -name *.html`; do \
	  sed "s|.google-analytics.com/ga.js|privacy/ga.js|g" -i $$f; \
	done
