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

pkgname=python-pycares
_name=${pkgname#python-}
pkgver=5.0.1
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=('27d60776f3063e6dfc344651625e8a526872d911c1e095571999d57b4897e59bc7583244a71462d98f27d607b66cc83dfd381db8a532980cff9195166330f0ac')

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
}
