# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Carlo Landmeter <clandmeter@alpinelinux.org>
pkgname=py3-img2pdf
pkgver=0.6.0
pkgrel=1
pkgdesc="Convert images to PDF via direct JPEG inclusion"
url="https://gitlab.mister-muffin.de/josch/img2pdf"
arch="noarch"
license="LGPL-3.0-or-later"
depends="python3 py3-pillow py3-pikepdf"
makedepends="py3-gpep517 py3-setuptools qpdf-dev libxml2-dev libxslt-dev
	py3-wheel"
checkdepends="coreutils exiftool ghostscript imagemagick mupdf-tools netpbm
	poppler-utils tiff-tools py3-lxml py3-numpy py3-scipy py3-pytest python3-dev"
subpackages="$pkgname-pyc"
source="https://pypi.python.org/packages/source/i/img2pdf/img2pdf-$pkgver.tar.gz"
builddir="$srcdir/img2pdf-$pkgver"

replaces=py-img2pdf # Backwards compatibility
provides=py-img2pdf=$pkgver-r$pkgrel # Backwards compatibility

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	# test_date: broken coreutils date call
	# test_{jpg,tiff,miff}_{cmyk,cmyk8,float}: fails with imagemagick >=7.1.1.41
	# https://gitlab.mister-muffin.de/josch/img2pdf/issues/204
	# https://gitlab.mister-muffin.de/josch/img2pdf/issues/205
	.testenv/bin/python3 -m pytest -k 'not test_date and not test_jpg_cmyk and not test_jpg_rot and not test_miff_cmyk8 and not test_tiff_cmyk8 and not test_tiff_float'
}

package() {
	# remove interpreter line from libraries
	# this is done after check() to not break the tests
	sed -i '/#!\//d' src/*.py

	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

sha512sums="
dbbeb7c3a5cb00b742681f127c724558971ef54628d47d044b1f1a9536d1cbe14b4a7ed2329e2e0f0ff57e85da8a8b826c32423a03d93b6c679b735e2fa06b54  img2pdf-0.6.0.tar.gz
"
