# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: David Runge <dvzrv@archlinux.org>

_name=aiosmtpd
pkgname=python-aiosmtpd
pkgver=1.4.6
pkgrel=1
pkgdesc="An asyncio based SMTP server"
arch=(any)
url="https://github.com/aio-libs/aiosmtpd"
license=(Apache-2.0)
depends=(
  python
  python-atpublic
  python-attrs
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(
  python-pytest
  python-pytest-asyncio
  python-pytest-mock
)
source=($_name-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz)
sha512sums=('ce920a3cf16920c4100f97db4630e738e9344e789042a8793d260d78f339e11917a42d9b438a43d2c73f259f0b83e47a98acc3d8ec8f34f0ff455b6a6a2cac09')
b2sums=('f196b633030582033769ac7aee8f95231e5387d9cfb8f5f52c7faeb86b72195e88879a096a19c967155f01d9c59c8f61b44a5f229056f2d1292f085ee98a181e')

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

check() {
  local pytest_options=(
    -vv
    -o addopts=""
    --deselect aiosmtpd/qa/test_0packaging.py::TestVersion::test_ge_master
  )

  cd $_name-$pkgver
  pytest "${pytest_options[@]}"
}

package() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 README.rst -t "${pkgdir}/usr/share/doc/${pkgname}"
  # remove unneeded stuff: https://github.com/aio-libs/aiosmtpd/issues/356
  rm -frv "$pkgdir/$_site_packages/$_name/"{docs,qa,tests}
}
