# Contributor: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Josh Holbrook <josh.holbrook@gmail.com>

pkgname=python-pyee
_name=${pkgname#python-}
pkgver=13.0.0
pkgrel=1
pkgdesc="Port of node.js's EventEmitter to python"
arch=(any)
url=https://github.com/jfhbrook/pyee
license=(MIT)
depends=(python-typing_extensions)
makedepends=(
  git
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(
  python-pytest-asyncio
  python-pytest-trio
  python-twisted
)
optdepends=(
  python-trio
  python-twisted
)
source=(git+https://github.com/jfhbrook/pyee#tag=v$pkgver)
sha256sums=('d44abfc1549ae13fb1c8b4325aae98aebff07bdc87475232162dc81e22f5700f')

build() {
  cd $_name
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd $_name
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest
}

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

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/"$_name"-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
