#!/usr/bin/make -f


SKIP=test_upload_file_egg \
     or test_web_preload \
     or test_dont_overlap_communications_to_same_worker \
     or test_share_communication \
     or test_robust_to_bad_sizeof_estimates \
     or test_broken_worker_during_computation \
     or test_profile_server \
     or test_feed_large_bytestring \
     or test_steal_expensive_data_slow_computation \
     or test_value_raises_during_spilling \
     or test_fail_write_to_disk \

# these failed when building, perhaps due to network issues?
# dont fail when run outside of the builder
SKIP+=or test_shutdown_localcluster \
      or test_nanny_closed_by_keyboard_interrupt \
      or test_preload_import_time \
      or test_tls_scheduler \
      or test_plugin_exception \
      or test_plugin_multiple_exceptions \
      or test_plugin_internal_exception \
      or test_interface_async \
      or test_host_uses_scheduler_protocol \
      or test_worker_listens_on_same_interface_by_default \
      or test_no_dangling_asyncio_tasks \

# this test fails on 32bit
SKIP+=or test_ensure_spilled_immediately \


export PYBUILD_NAME=distributed
export PYBUILD_TEST_ARGS=$(CURDIR)/distributed/tests -v \
  --ignore=distributed/deploy/utils_test.py \
  --ignore=distributed/utils_test.py \
  --ignore=continuous_integration \
  --ignore=docs \
  --ignore=.github \
  --timeout-method=signal \
  --timeout=300 \
  -m "not (avoid_travis or isinstalled or slow or flaky)" -k "not ( $(SKIP) )"

export NEEDED_JS=distributed/http/static/js/anime.js \
                 distributed/http/static/js/reconnecting-websocket.js
DEB_BUILD_OPTIONS += $(filter nodoc,$(DEB_BUILD_PROFILES))
%:
	dh $@ --with python3,sphinxdoc --buildsystem=pybuild

override_dh_auto_build: export http_proxy=127.0.0.1:9
override_dh_auto_build: export https_proxy=127.0.0.1:9
override_dh_auto_build:
	rm -f distributed/comm/tests/__init__.py
	set -e; \
	for p in ${NEEDED_JS}; do \
	    uglifyjs -o $$p debian/missing-sources/$$p ; \
	done
	chmod a-x distributed/tests/test_utils_test.py
	dh_auto_build
#	ln -s /usr/share/javascript/mathjax docs/source/_static
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. python3 -m sphinx -N -bhtml docs/source build/html # HTML generator
endif
	dh_fixperms

override_dh_compress:
	dh_compress -Xchangelog.html

override_dh_install:
	dh_install
	dh_installchangelogs docs/source/changelog.rst

override_dh_auto_install:
	dh_auto_install
	dh_link
	find debian/ -name *.ico -exec chmod a-x {} \;
	rm -rf debian/python3-distributed/usr/lib/python3*/dist-packages/dask-worker-space

override_dh_auto_clean:
	touch distributed/comm/tests/__init__.py
	dh_auto_clean
	-rm $(NEEDED_JS)
	-chmod 755 distributed/tests/test_utils_test.py
