# Maintainer:
# Contributor: @RubenKelevra <cyrond@gmail.com>

pkgname=python-watchfiles
_name=${pkgname#python-}
pkgver=0.21.0
pkgrel=3
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=(
  gcc-libs
  glibc
  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=('299ab53edde696315fff1c1bdb63d45badb008e990bfb7367d5599e9f2e79c0aafbb761a21aa56c6c4e1dc4697f7ae20a868aff0a302e8393321f143cea048c0')

prepare() {
  # remove __init__.py otherwise this prevents tests detecting the watchfiles module anywhere else
  rm -v $_name-$pkgver/tests/__init__.py
}

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

check() {
  local pytest_options=(
    -vv
    -o addopts=''
    --deselect tests/test_watch.py::test_awatch_interrupt_raise
  )
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="$PWD/test_dir/$site_packages:$PYTHONPATH"
  pytest "${pytest_options[@]}" .
}

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