# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=fava
pkgver=1.28
pkgrel=0
pkgdesc="Web interface for Beancount"
url="https://beancount.github.io/fava/"
arch="noarch"
license="MIT"
depends="
	beancount
	python3
	py3-babel
	py3-flask
	py3-flask-babel
	py3-jinja2
	py3-werkzeug
	py3-cheroot
	py3-click
	py3-markdown2
	py3-ply
	py3-simplejson
	py3-watchfiles
	"
makedepends="
	npm
	nodejs
	py3-gpep517
	py3-setuptools
	py3-setuptools_scm
	py3-wheel
	"
checkdepends="py3-pytest"
subpackages="$pkgname-pyc"
source="$pkgname-$pkgver.tar.gz::https://github.com/beancount/fava/archive/refs/tags/v$pkgver.tar.gz"

prepare() {
	default_prepare

	# static files aren't detected to be included in the wheel file
	echo "recursive-include src/fava *.html *.js *.md beancount_file" >> MANIFEST.in

	cd frontend
	npm install --no-progress
}

build() {
	cd frontend
	npm run build
	cd ..

	export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
	pybabel compile -d src/fava/translations
	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_cli.py requires fava to be available inside PATH
	# test_core_watcher.py fails on aarch64, armhf, armv7 and ppc64le
	.testenv/bin/python3 -m pytest \
		--ignore=tests/test_cli.py \
		--ignore=tests/test_core_watcher.py
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

sha512sums="
4abdcb827a4bcf7510d39c29259072046f4a53dc9bc03e42b359f8823b3c114645a698b446a75fc8e16f436642b6e1fbfc79ee5745d291d614734b65594fa19f  fava-1.28.tar.gz
"
