#!/usr/bin/make -f

export DH_VERBOSE = 1

%:
	dh $@ --buildsystem=pybuild

execute_after_dh_auto_build:
	# pybuild calls:
	# python3.11 -m build --skip-dependency-check --no-isolation --wheel --outdir OUTDIR
	# And in the file top_level.txt it includes directories of the root of the package:
	# ping3 (wanted), debian (not wanted), build (if it exists, not wanted)
	#
	# Removes "debian" and "build"
	# Not doing it makes top_level.txt of Python3.11 and Python3.12 be different, then the file
	# in the installed package:
	# /usr/lib/python3.12/dist-packages/ping3-4.0.4.dist-info/
	# /usr/lib/python3/dist-packages/ping3-4.0.4.dist-info/
	# Lintian raises:
	# W: python3-ping3: python-module-in-wrong-location usr/lib/python3.12/dist-packages/ping3-4.0.4.dist-info -> usr/lib/python3/dist-packages/ping3-4.0.4.dist-info
	# I: python3-ping3: package-contains-documentation-outside-usr-share-doc [usr/lib/python3.12/dist-packages/ping3-4.0.4.dist-info/top_level.txt]
	sed -i '/\(^debian$$\|^build$$\)/d' .pybuild/cpython3_*/build/ping3-*.dist-info/top_level.txt

	# Delete files that are duplicated and not needed in the file
	# (not doing it raises a Lintian error:
	# P: python3-ping3: repeated-path-segment lib [usr/lib/python3/dist-packages/build/lib/]
	rm -rf .pybuild/cpython3_*/build/build/lib
