#!/usr/bin/make -f

export PYBUILD_NAME=memray
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Disabled tests that need depends not available in Debian (pytest-textual-snapshot).
# Last 4 10s timeout failure in build i386
# 8th from last due to socket issue freeze.
export PYBUILD_TEST_ARGS = \
	-v -k 'not test_basic \
	and not test_basic_node_selected_not_leaf \
	and not test_basic_node_selected_leaf \
	and not test_two_chains \
	and not test_two_chains_after_expanding_second \
	and not test_hide_import_system \
	and not test_show_uninteresting \
	and not test_show_uninteresting_and_hide_import_system \
	and not test_select_screen \
	and not test_allocations_of_different_sizes \
	and not test_biggest_allocations \
	and not test_tui_basic[narrow-terminal-short-snapshots] \
	and not test_tui_basic[narrow-terminal-focus-header-long-snapshots] \
	and not test_tui_basic[wide-terminal-long-snapshots] \
	and not test_tui_basic[very-wide-terminal-short-snapshots] \
	and not test_tui_pause[narrow-terminal-connected] \
	and not test_tui_pause[narrow-terminal-disconnected] \
	and not test_tui_pause[wider-terminal] \
	and not test_tui_gradient \
	and not test_multithreaded_extension_with_native_tracking \
	and not test_simple_call_chain_with_native_tracking \
	and not test_inlined_call_chain_with_native_tracking \
	and not test_deep_call_chain_with_native_tracking \
	and not test_hybrid_stack_in_pure_python \
	and not test_hybrid_stack_in_pure_python_with_callbacks \
	and not test_hybrid_stack_of_allocations_inside_ceval \
	and not test_hybrid_stack_in_recursive_python_c_call \
	and not test_hybrid_stack_in_a_thread \
	and not test_hybrid_stack_of_python_thread_starts_with_native_frames \
	and not test_pymalloc_allocations_after_fork \
	and not test_aggregation_same_python_stack_but_different_native_stack[ALL_ALLOCATIONS] \
	and not test_aggregation_same_python_stack_but_different_native_stack[AGGREGATED_ALLOCATIONS] \
	and not test_reading_allocations_while_reading_stack_traces \
	and not test_allocations_with_multiprocessing \
	and not test_allocations_with_multiprocessing_following_fork \
	and not test_stack_cleanup_after_fork \
	and not test_live_tracking_waits_for_client \
	and not test_live_tracking'

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

override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--warnings=9

override_dh_auto_install:
	dh_auto_install
	# Strip unneeded symbols and notes from shared libraries
	find debian/python3-memray -name "*.so*" -exec strip --strip-unneeded --remove-section=.note.gnu.build-id {} +

override_dh_install:
	dh_install
	mkdir -p debian/python3-memray/usr/lib/python3/dist-packages/
	mv debian/python3-memray/usr/lib/python3.12/dist-packages/memray-1.11.0.egg-info debian/python3-memray/usr/lib/python3/dist-packages/
	rm -rf debian/python3-memray/usr/lib/python3.11/dist-packages/memray-1.11.0.egg-info
	rm -f debian/python3-memray/usr/bin/memray3.11
	rm -f debian/python3-memray/usr/bin/memray3.12
	rm -f debian/python3-memray/usr/bin/memray

override_dh_installdocs:
	https_proxy='127.0.0.1:9' sphinx-build -b html docs build/sphinx/html
	dh_installdocs -ppython-memray-doc --doc-main-package=python-memray-doc build/sphinx/html
	dh_installdocs
