# Template file for 'calibre'
pkgname=calibre
version=5.9.0
revision=2
build_style=python3-module
pycompile_dirs="/usr/lib/calibre/"
hostmakedepends="pkg-config python3-BeautifulSoup4 python3-Pillow python3-PyQt5-svg
 python3-PyQt5-webengine python3-apsw python3-css-parser python3-dateutil
 python3-devel python3-html5-parser python3-msgpack python3-regex qt5-qmake
 libpodofo-devel python3-PyQt-builder python3-PyQt5-devel qt5-host-tools
 python3-zeroconf xdg-utils rapydscript-ng"
makedepends="libinput-devel libmagick-devel libmtp-devel
 libpodofo-devel libwmf-devel libxkbcommon-devel python3-PyQt5-devel
 qt5-devel sqlite-devel tslib-devel hunspell-devel hyphen-devel"
depends="desktop-file-utils optipng poppler-utils python3-BeautifulSoup4
 python3-Markdown python3-Pillow python3-PyQt5-svg python3-zeroconf
 python3-PyQt5-webengine python3-PyQt5-webchannel python3-Pygments python3-apsw
 python3-css-parser python3-cssselect python3-dateutil python3-dbus
 python3-dnspython python3-feedparser python3-html5-parser python3-mechanize
 python3-msgpack python3-netifaces python3-psutil python3-regex python3-html2text
 python3-pychm qt5-webengine speech-dispatcher"
# should check if python3-pycryptodome is still needed
checkdepends="${depends} libjpeg-turbo-tools jxrlib python3-pycryptodome"
short_desc="Ebook management application"
maintainer="skmpz <dem.procopiou@gmail.com>"
license="GPL-3.0-only"
homepage="https://calibre-ebook.com"
changelog="https://raw.githubusercontent.com/kovidgoyal/calibre/master/Changelog.yaml"
distfiles="https://download.calibre-ebook.com/${version}/calibre-${version}.tar.xz"
checksum=a71196af15372054c4a25697534a2df1ef6dd732b9db07aaecaac7a86d9b3a0a
lib32disabled=yes
nocross=yes

do_configure() {
	# Remove unneeded files and libs
	rm -rf resources/${pkgname}-portable.*

	# Desktop integration (e.g. enforce arch defaults)
	vsed -i src/calibre/linux.py \
		-e "/import config_dir/,/os.rmdir(config_dir)/d" \
		-e "s/'ctc-posml'/'text' not in mt and 'pdf' not in mt and 'xhtml'/" \
		-e "s/^Name=calibre/Name=Calibre/g"
}

do_build() {
	python3 setup.py build
	python3 setup.py gui
	python3 setup.py rapydscript
}

do_check() {
	# qt test crashes without any error messages
	# disabled for now
	# unrar test fails because python3-unrardll isn't packaged
	# searching test case fails (non-deterministic)
	python3 setup.py test \
		--exclude-test-name unrar \
		--exclude-test-name qt \
		--exclude-test-name searching
}

do_install() {
	vmkdir usr/share/zsh/site-functions

	python3 setup.py \
		install --prefix=/usr --staging-root=${DESTDIR}/usr

	for m in man-pages/man1/*.1; do
		vman "${m}"
	done
}
