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

pkgname=python-anyio
# https://github.com/agronholm/anyio/blob/master/docs/versionhistory.rst
pkgver=4.11.0
pkgrel=1
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=(git 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
              python-truststore python-exceptiongroup)
optdepends=(
  'python-trio: trio backend'
  'python-outcome: trio backend'
  'python-uvloop: use uvloop for asyncio backend'
  'python-pytest: pytest plugin'
)
source=("git+https://github.com/agronholm/anyio.git#tag=$pkgver")
sha256sums=('04b055c49ed37aa952a7a40501ccc073850d6926f602a1073cb37b22c0a4d2df')

export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver

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

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

check() {
  cd anyio
  # 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
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
}
