#!/usr/bin/make -f

# This package uses dh_virtualenv to install package a venv with PyHSS and a
# few vendored python packages that are not available in Debian. The vendored
# packages get downloaded with debian/pyhss_download_deps.sh first, so they can
# be part of the source package before performing the actual build offline.
ifeq ("$(wildcard debian/deps)","")
$(error debian/deps is missing, run debian/pyhss_download_deps.sh first)
endif

export PIP_NO_INDEX=1
export PIP_FIND_LINKS=debian/deps
export PIP_QUIET=0
export PIP_VERBOSE=1

%:
	dh $@ --with python-virtualenv

override_dh_virtualenv:
# In order to be able to use debian-packaged dependencies, we cannot have exact
# version requirements
	sed 's/==.*//g' requirements.txt >requirements-without-versions.txt
# Install pyhss and all vendored dependencies into a venv
	dh_virtualenv \
		--builtin-venv \
		--python python3 \
		--requirements=requirements-without-versions.txt \
		--use-system-packages
# Save space in the binary package by uninstalling build-time depends
	debian/pyhss/opt/venvs/pyhss/bin/python \
		-m pip \
		uninstall \
		--yes \
		pip \
		setuptools \
		setuptools-scm \
		vcs-versioning \
		wheel
# Run testsuite
	( . debian/pyhss/opt/venvs/pyhss/bin/activate && \
	  python3 -m pytest -xvv -m "not skip_packaging")
# Clean up
	rm requirements-without-versions.txt

# dh_installsysusers needs to be explicitly called until debhelper-compat >= 14
override_dh_install:
	dh_install
	dh_installsysusers
