#!/usr/bin/make -f

export PYBUILD_NAME=thonny

# Needed by fontconfig during tests
export HOME=$(CURDIR)/debian/fakehome/

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

override_dh_auto_test:
	xvfb-run --auto-servernum python3 -m pytest thonny/test

override_dh_install:
	dh_install

	# Move image resources to /usr/share as per FHS
	# For two locations: res and plugins/pi/res
	rm -rf debian/thonny/usr/lib/python3*/dist-packages/thonny/res
	mkdir -p debian/thonny/usr/lib/python3/dist-packages/thonny
	ln -s /usr/share/thonny/res debian/thonny/usr/lib/python3/dist-packages/thonny/res

	rm -rf debian/thonny/usr/lib/python3*/dist-packages/thonny/plugins/pi/res
	mkdir -p debian/thonny/usr/lib/python3/dist-packages/thonny/plugins/pi
	ln -s /usr/share/thonny/plugins/pi/res debian/thonny/usr/lib/python3/dist-packages/thonny/plugins/pi/res

execute_after_dh_auto_install:
	find debian/thonny -name .DS_Store -delete
	# Notes on what to test should go to documentation via d/thonny.docs and not be installed in dist-packages
	rm debian/thonny/usr/lib/python3*/dist-packages/thonny/test/what_to_test.txt

execute_after_dh_fixperms:
	chmod -x debian/thonny/usr/lib/python3/dist-packages/thonny/locale/register_updates.py
	chmod -x debian/thonny/usr/lib/python3/dist-packages/thonny/plugins/system_shell/explain_environment.py
