#!/usr/bin/make -f

export PYBUILD_NAME=mistral-common

# Disable some tests
# - python3-llguidance is required by these tests but not yet packaged
# - sentencepiece tests require to download a model/vocabulary
#    src/mistral_common/data/mistral_instruct_tokenizer_241114.model.v7
export PYBUILD_TEST_ARGS=\
--ignore=tests/guidance/ \
--ignore=tests/test_sentencepiece.py

# Prepare assets needed by the tests
export PYBUILD_BEFORE_TEST=\
	cp -r $(CURDIR)/docs/ $(CURDIR)/scripts/ {build_dir} \
	&& mkdir -p {build_dir}/src/mistral_common/data

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

execute_after_dh_auto_build:
	mkdocs build --site-dir=html

	# Remove privacy-breaching Google fonts from documentation
	# TODO patch mkdocs.yml to have 'fonts: false' ? 
	find html/ \
	 -type f -name "*.html" -exec sed -i '/fonts\.gstatic\.com/d' {} +
	find html/ \
	 -type f -name "*.html" -exec sed -i '/fonts\.googleapis\.com/d' {} +

override_dh_auto_install:
	dh_auto_install
	
	# Removes CLI for the time being as it seems experimental
	# and could cause confusion with unrelated software also called 'mistral'
	rm -r debian/python3-mistral-common/usr/bin/
	
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Remove assets which had been copied for the tests by PYBUILD_BEFORE_TEST
	rm -r debian/python3-mistral-common/usr/lib/python3.*/dist-packages/docs/
	rm -r debian/python3-mistral-common/usr/lib/python3.*/dist-packages/scripts/
endif
