# Template file for 'calibre'
pkgname=calibre
version=5.44.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 libstemmer-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-jeepney
 python3-dnspython python3-feedparser python3-html5-parser python3-mechanize
 python3-msgpack python3-netifaces python3-psutil python3-regex python3-html2text
 python3-pychm python3-cchardet qt5-webengine speech-dispatcher python3-sgmllib"
# 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.txt"
distfiles="https://download.calibre-ebook.com/${version}/calibre-${version}.tar.xz"
checksum=6ffaa3eafd36a24355e5957f0f838db6db6d3456cfa17cb4d139fd94ebaf88ec
python_version=3
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)
	# 7z tests disabled (missing python-py7zr dependencies)
	# test_dom_load case fails
	python3 setup.py test \
		--exclude-test-name unrar \
		--exclude-test-name qt \
		--exclude-test-name searching \
		--exclude-test-name 7z \
		--exclude-test-name test_dom_load
}

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
}
