#!/usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE = 1

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

PYTHON_GRIFFE_PACKAGES=\
griffecli \
griffelib \

export PYBUILD_TEST_ARGS=\
 --ignore tests/test_api.py \
 -k 'not test_load_git \
 and not test_load_git_errors \
 '

export PDM_BUILD_SCM_VERSION = $(DEB_VERSION_UPSTREAM)
export TMP_DIST-PACKAGES_FOLDER=$(CURDIR)/.pybuild/dist-packages/build

%:
	dh $@ --buildsystem=pybuild

override_dh_clean:
	dh_clean
	rm -rf .pdm-build

override_dh_auto_build:
	for PYTHON_GRIFFE_PACKAGE in $(PYTHON_GRIFFE_PACKAGES); do \
	    echo "\n########\n# Building package $${PYTHON_GRIFFE_PACKAGE}\n########" ;\
	    PYBUILD_NAME=$${PYTHON_GRIFFE_PACKAGE} ;\
	    dh_auto_build --buildsystem=pybuild --sourcedirectory packages/$${PYTHON_GRIFFE_PACKAGE} -- --name=$${PYTHON_GRIFFE_PACKAGE} ;\
	done
	# Collect all built libraries and copy them into a temporary folder
	# so the testsuite can find the right modules.
	mkdir .pybuild/dist-packages && \
	for FOLDER in `find .pybuild/cpython3_3.*griffe*/ -maxdepth 1 -type d -name build`; do \
	    echo "Copy $${FOLDER} -> .pybuild/dist-packages" ;\
	    cp -a $${FOLDER} .pybuild/dist-packages ;\
	done

override_dh_auto_install:
	for PYTHON_GRIFFE_PACKAGE in $(PYTHON_GRIFFE_PACKAGES); do \
	    echo "\n########\n# Installing package $${PYTHON_GRIFFE_PACKAGE}\n########" ;\
	    PYBUILD_NAME=$${PYTHON_GRIFFE_PACKAGE} ;\
	    dh_auto_install --buildsystem=pybuild --sourcedirectory packages/$${PYTHON_GRIFFE_PACKAGE} -- --name=$${PYTHON_GRIFFE_PACKAGE} ;\
	done

override_dh_auto_test:
	PYTHONPATH=$(TMP_DIST-PACKAGES_FOLDER) python3 -m pytest $(PYBUILD_TEST_ARGS)
