# Contributor: Newbyte <newbyte@disroot.org>
# Maintainer: JuniorJPDJ <alpine@juniorjpdj.pl>
pkgname=py3-watchfiles
pkgver=0.22.0
pkgrel=0
pkgdesc="Simple, modern file watching and code reload in Python"
url="https://github.com/samuelcolvin/watchfiles"
arch="all"
license="MIT"
depends="py3-anyio"
makedepends="
	cargo
	maturin
	py3-gpep517
	py3-maturin
	"
checkdepends="py3-pytest py3-pytest-asyncio py3-pytest-mock py3-pytest-toolbox py3-pytest-timeout py3-dirty-equals"
subpackages="$pkgname-pyc"
source="$pkgname-v$pkgver.tar.gz::https://github.com/samuelcolvin/watchfiles/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/watchfiles-$pkgver"
options="net" # cargo fetch

prepare() {
	default_prepare

	# set correct version in Cargo.toml
	VERSION="$pkgver" .github/set_version.py
	# update version in Cargo.lock
	cargo update -p watchfiles_rust_notify
	cargo fetch --locked
}

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--config-json '{"build-args": "--frozen"}' \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl

	cd .testenv
	# Fails on slow systems or when system is under heavy load.
	# See upstream issue #84
	# test_awatch_interrupt_raise: loops while trying to handle the exception
	# maybe due anyio 4
	# https://github.com/samuelcolvin/watchfiles/issues/254
	# According to .github/workflows/ci.yml,
	# WATCHFILES_TEST_PERMISSION_DENIED_PATH is set to a directory owned by
	# root with chmod 700, in alpine-baselayout /root fits this criteria
	WATCHFILES_TEST_PERMISSION_DENIED_PATH=/root \
	bin/python3 -m pytest --import-mode=importlib -k 'not test_awatch_log and not test_awatch_interrupt_raise' ..
}

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

sha512sums="
6d3a4478ff90697323e84428fa16db4b8355c7c637e4faa00a025ff1e03fe8f44914fedb2943a6b6b6cad13bdf50bb6e5712de9caa34b66eb64193923eed6504  py3-watchfiles-v0.22.0.tar.gz
"
