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

pkgname=python-pycares
_name=${pkgname#python-}
pkgver=4.4.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"
        update-dns-response.patch
        update-for-ares-1.28.patch
        0001-Update-test_query_txt_chunked-expected-results-due-t.patch)
b2sums=('SKIP'
        'SKIP'
        'SKIP'
        'SKIP')

prepare() {
  cd "$_name"
  patch -Np1 -i ../update-for-ares-1.28.patch
  patch -Np1 -i ../0001-Update-test_query_txt_chunked-expected-results-due-t.patch
}

build() {
  cd "$_name"
  PYCARES_USE_SYSTEM_LIB=1 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 -v -k 'not test_gethostbyaddr and not test_gethostbyaddr6 and not test_getnameinfo'
}

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
}
