# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

pkgname=python-pycares
_name=${pkgname#python-}
pkgver=4.11.0
pkgrel=1
pkgdesc='Python interface for c-ares'
arch=(x86_64 aarch64)
url=https://github.com/saghul/pycares
license=(MIT)
depends=(
  c-ares
  python-cffi
)
makedepends=(
  git
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(
  python-idna
  python-pytest
)
optdepends=(python-idna)
source=("git+$url.git#tag=v$pkgver")
b2sums=('ac946aca6a2be3784da24e781c7da43965945e38f0b8ee639da3153cc7634333d510d04fd858c21558811a42dc11168fd01c9fa1edb14bdbb1b9718504bb8fa4')

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

check() {
  local pytest_options=(
    -vv
    --deselect tests/test_all.py::DNSTest::test_gethostbyaddr
    --deselect tests/test_all.py::DNSTest::test_gethostbyaddr6
    --deselect tests/test_all.py::DNSTest::test_getnameinfo
    --deselect tests/test_all.py::DNSTest::test_query_txt_chunked
  )

  cd "$_name"
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest "${pytest_options[@]}"
}

package() {
  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/licenses/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname

  cd "$_name"
  python -m installer --destdir="$pkgdir" dist/*.whl
}
