# Contributor: August Klein <amatcoder@gmail.com>
# Contributor: Antoine Fontaine <antoine.fontaine@epfl.ch>
# Maintainer: fossdd <fossdd@pwned.life>
pkgname=deluge
pkgver=2.1.1
pkgrel=10
pkgdesc="lightweight, Free Software, cross-platform BitTorrent client"
url="https://deluge-torrent.org/"
arch="noarch"
license="GPL-3.0-or-later"
_depends_ui="
	gtk+3.0
	librsvg
	py3-cairo
	py3-gobject3
	xdg-utils
	"
depends="
	py3-chardet
	py3-distro
	py3-idna
	py3-libtorrent-rasterbar
	py3-mako
	py3-openssl
	py3-pillow
	py3-rencode
	py3-service_identity
	py3-setproctitle
	py3-setuptools
	py3-twisted
	py3-wheel
	py3-xdg
	py3-zope-interface
	"
makedepends="
	py3-gpep517
	py3-installer
	py3-rjsmin
	$_depends_ui
	"
checkdepends="
	py3-mock
	py3-pytest
	"
options="!check" # failing ui off-by-one size tests, segfault in another
subpackages="$pkgname-doc $pkgname-gtk $pkgname-pyc"
source="http://download.deluge-torrent.org/source/${pkgver%.*}/deluge-$pkgver.tar.xz
	deluge.desktop
	"

replaces="$pkgname-lang" # Overwrite removed subpackage

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

check() {
	pytest
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/deluge-$pkgver-py3-none-any.whl

	install -Dm644 "$srcdir"/deluge.desktop \
		-t "$pkgdir"/usr/share/applications/

	rm -r "$pkgdir"/usr/share/pixmaps
}

gtk() {
	pkgdesc="$pkgdesc (gtk ui)"
	depends="$pkgname=$pkgver-r$pkgrel $_depends_ui"

	amove usr/share
	amove usr/bin/deluge-gtk
	amove usr/lib/python3*/site-packages/deluge/ui/gtk3
}

sha512sums="
e94208981aee45f42b88e1c544b07e7b0d0f2c4ade6b7f37257b69d4a3394c89aff217cde699e79ad59de6d2ee4eca7a558f2b85505d2140ba73f1f76f184455  deluge-2.1.1.tar.xz
003696606e6114baca618e734d283acaebeec2c49ece82b0bcf385e026149a38943c82b270a6b0ab7b30e80640365a750cc275ea9a6b7e67078d10cfd3ef87a5  deluge.desktop
"
