# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=python-nest-asyncio
pkgver=1.6.0
pkgrel=5
pkgdesc="Patch asyncio to allow nested event loops"
url="https://github.com/erdewit/nest_asyncio"
license=('BSD-2-Clause')
arch=('any')
depends=('python')
makedepends=('git' 'python-setuptools-scm' 'python-setuptools' 'python-build' 'python-installer' 'python-wheel')
provides=('python-nest_asyncio')
replaces=('python-nest_asyncio')
source=(
  "git+https://github.com/erdewit/nest_asyncio.git#tag=v$pkgver"
  "$pkgname-remove-failing-test.patch"
)
sha512sums=('b85ca536a8a1fb47af09a30b0084034860bd483249e22e0d452966383bd5108138096a94ea03bd529a07b719b8f4f15bcb05892e2dfc399f47f1fcce74940b12'
            'e523767d8ee33d47d3535d5eaf69ccf173427379a9b8b419e60da44bc9f4d105e40e89fdfe9bd474a2955e1df271b65fb06663d551591afbfb19ea8feae341d3')

prepare() {
  cd nest_asyncio
  patch -Np1 < ../$pkgname-remove-failing-test.patch
  # Rename test file to conform with unittest discovery
  mv -v tests/nest_test.py tests/test_nest.py
}

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

check() {
  cd nest_asyncio
  PYTHONPATH="$PWD/build/lib" python -m unittest discover -v
}

package() {
  cd nest_asyncio
  python -m installer --destdir="$pkgdir" dist/*.whl

  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
