# Maintainer: Chih-Hsuan Yen <yan12125@archlinux.org>

pkgname=python-anyio
# https://github.com/agronholm/anyio/blob/master/docs/versionhistory.rst
pkgver=4.3.0
pkgrel=3
pkgdesc='High level compatibility layer for multiple asynchronous event loop implementations'
arch=(any)
url='https://github.com/agronholm/anyio'
license=(MIT)
depends=(python python-idna python-sniffio)
makedepends=(python-build python-installer python-setuptools python-setuptools-scm python-wheel
             python-uvloop python-trio)
checkdepends=(python-pytest python-trustme python-hypothesis python-pytest-mock python-psutil)
optdepends=(
  'python-trio: trio backend'
  'python-outcome: trio backend'
  'python-uvloop: use uvloop for asyncio backend'
  'python-pytest: pytest plugin'
)
source=(https://github.com/agronholm/anyio/archive/$pkgver/anyio-$pkgver.tar.gz)
sha256sums=('795c49397862065e6650d6bc30d5ccfd4bc149f8a4f9fbdbe3d816b8aaf5fb21')

export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver

prepare() {
  cd anyio-$pkgver
  # Remove "error" from pytest filterwarnings
  sed -i '/"error"/d' pyproject.toml
}

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

check() {
  cd anyio-$pkgver
  # Install to a temporary root as the test suite requires the entry point for
  # its pytest plugin
  pyver=$(python -c "import sys; print('{}.{}'.format(*sys.version_info[:2]))")
  python -m installer --destdir="$PWD/tmp_install" dist/*.whl
  PYTHONPATH="$PWD/tmp_install/usr/lib/python$pyver/site-packages" pytest
}

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