#!/usr/bin/make -f
#export DH_VERBOSE=1
#export DEB_BUILD_OPTIONS=nocheck
export PYBUILD_NAME=keras

export KERAS_BACKEND=theano
export THEANO_FLAGS=base_compiledir='.pybuild',device=cpu
export PYTHONDONTWRITEBYTECODE=1

export LC_ALL=C.UTF-8
export LANG=C.UTF-8

# require tensorflow but not SKIPPED
TESTSTOIGNORE=\
  tests/keras/layers/cudnn_recurrent_test.py \
  tests/keras/utils/multi_gpu_test.py

# failure: ActivityRegularizer class doesn't have any documentation
TESTSTOIGNORE+=tests/test_documentation.py

# internal failure, bad function calls
TESTSTOIGNORE+=\
  tests/integration_tests/test_image_data_tasks.py \
  tests/integration_tests/test_temporal_data_tasks.py \
  tests/keras/applications/imagenet_utils_test.py \
  tests/keras/backend/backend_test.py

# need to access the internet
TESTSTOIGNORE+=\
  tests/keras/applications/imagenet_utils_test.py \
  tests/keras/datasets/test_datasets.py

IGNORETESTS=$(TESTSTOIGNORE:%=--ignore=%)

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

override_dh_auto_build-indep:
	dh_auto_build
# In the PyPI distribution the file CONTRIBUTING.md is missing, which
# causes an error during doc build, so make it an empty file.
	cd docs && sh -c "env PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=.. python3 autogen.py && mkdocs build --site-dir=html"
# Despite PYTHONDONTWRITEBYTECODE, a __pycache__ is nonetheless generated by mkdocs!
	find . -type d -name __pycache__ | xargs rm -rfv
# Distributed docs should not contain any programs
	rm -fv docs/html/*.py

override_dh_auto_test:
# Run tests using Theano backend and CPU device.
# Not every test is expected to pass, so we run a subset here:
	PYBUILD_SYSTEM=custom PYBUILD_TEST_ARGS="PYTHONPATH=.pybuild/pythonX.Y_{version}/build py.test-3 -oaddopts=-v $(IGNORETESTS)" dh_auto_test

override_dh_installdocs:
	markdown README.md > .pybuild/README.html
	links -dump .pybuild/README.html > .pybuild/README
	dh_installdocs -A .pybuild/README

override_dh_compress:
	dh_compress -X.py
