#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

# Debian separates prerelease suffixes with a tilde, which Poetry rejects.
PYTHON_UPSTREAM_VERSION = $(subst ~,,$(DEB_VERSION_UPSTREAM))

export PYBUILD_TEST_ARGS=--no-cov

%:
	dh $@ --buildsystem=pybuild

override_dh_auto_build:
	# Use the changelog version in the wheel, then restore the source files.
	set -e; \
	backup_dir=$$(mktemp -d); \
	cp -p pyproject.toml airthings_ble/__init__.py "$$backup_dir/"; \
	trap 'mv "$$backup_dir/pyproject.toml" pyproject.toml; mv "$$backup_dir/__init__.py" airthings_ble/__init__.py; rmdir "$$backup_dir"' EXIT; \
	sed -i 's/^version = ".*"$$/version = "$(PYTHON_UPSTREAM_VERSION)"/' pyproject.toml; \
	sed -i 's/^__version__ = ".*"$$/__version__ = "$(PYTHON_UPSTREAM_VERSION)"/' airthings_ble/__init__.py; \
	dh_auto_build
