# Maintainer: Carl Smedstad <carsme@archlinux.org>
# Contributor: @RubenKelevra <cyrond@gmail.com>

pkgname=python-watchfiles
pkgver=1.2.0
pkgrel=1
pkgdesc='Simple, modern and high performance file watching and code reload in Python'
arch=(x86_64 aarch64)
url='https://github.com/samuelcolvin/watchfiles'
license=(MIT)
depends=(
  glibc
  libgcc
  python
  python-anyio
)
makedepends=(
  python-build
  python-installer
  python-maturin
)
checkdepends=(
  python-dirty-equals
  python-pytest
  python-pytest-mock
  python-pytest-timeout
)
source=("$url/archive/v$pkgver/$pkgname-$pkgver.tar.gz")
b2sums=('5e1de15036e911588293024dcc6c95e752517e23f0023537841074e4eeb9a937c037d5187788c0c9de30350c6a70b324f452b81d11b9a0bab5d875e527aac8b7')

prepare() {
  cd ${pkgname#python-}-$pkgver
  # This prevents tests from detecting the watchfiles module.
  rm -v tests/__init__.py
}

build() {
  cd ${pkgname#python-}-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd ${pkgname#python-}-$pkgver
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  # Don't add CWD to PYTHONPATH, the watchfiles package in CWD will take
  # precedence over installed one.
  test-env/bin/python -Im pytest
}

package() {
  cd ${pkgname#python-}-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
