#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export PYBUILD_NAME=sorl-thumbnail

%:
	dh $@ --buildsystem=pybuild

override_dh_clean:
	rm -rf .build tmp-locales tests/media/
	dh_clean

pytest_args := -o usefixtures=transactional_db
# Currently broken.
pytest_args += --deselect tests/thumbnail_tests/test_templatetags.py::TemplateTestCaseA::test_orientation
# Remote resources such as images fetched over HTTP are not allowed at build
# time.
pytest_args += \
        --deselect tests/thumbnail_tests/test_engines.py::SimpleTestCase::test_image_file_deserialize \
        --deselect tests/thumbnail_tests/test_filters.py::FilterTestCase::test_html_filter \
        --deselect tests/thumbnail_tests/test_filters.py::FilterTestCase::test_markdown_filter \
        --deselect tests/thumbnail_tests/test_templatetags.py::TemplateTestCaseB::test_url \
        --deselect tests/thumbnail_tests/test_templatetags.py::TemplateTestCaseB::test_portrait

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	mkdir -p tmp-locales
	localedef -i en_US -c -f UTF-8 tmp-locales/en_US.UTF-8
	set -e; \
	for python in $(shell py3versions -r); do \
	    for name in pil pgmagick imagemagick graphicsmagick; do \
	        LOCPATH=$(CURDIR)/tmp-locales LC_ALL=en_US.UTF-8 PYTHONPATH=. LOCAL_BUILD=1 DJANGO_SETTINGS_MODULE=tests.settings.$$name $$python -m pytest $(pytest_args); \
	    done; \
	done
	rm -rf tmp-locales
endif

override_dh_installchangelogs:
	dh_installchangelogs -- CHANGES.rst

override_dh_installdocs:
	PYTHONPATH=.:$$PYTHONPATH python3 -m sphinx -b html -d .build/.doctrees -N docs .build/html
	dh_installdocs -ppython-sorl-thumbnail-doc --doc-main-package=python-sorl-thumbnail-doc
	dh_installdocs --remaining-packages
