# Maintainer: Luke Shumaker <lukeshu@parabola.nu>
# Maintainer (aur:python-pydns): Sebastien Leduc <sebastien@sleduc.fr>
# Contributor: Samed Beyribey <ras0ir AT eventualis DOT org>

pkgname=python-py3dns
_pkgname=${pkgname#python-}
pkgver=4.0.0
pkgrel=1
pkgdesc="A module for looking up DNS entries in Python applications"
arch=('any')
url="https://launchpad.net/${_pkgname}"
license=('custom:PSF-like')

makedepends=('python-build' 'python-installer' 'python-wheel' 'python-flit')

source=("https://launchpad.net/${_pkgname}/trunk/${pkgver}/+download/${_pkgname}-${pkgver}.tar.gz"{,.asc})
md5sums=('1dddc2621ced329a84a814eae1f92a39'
         'SKIP')
validpgpkeys=('E7729BFFBE85400FEEEE23B178D7DEFB9AD59AF1') # Donald Scott Kitterman

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

check() {
  if ! getent hosts parabola.nu >/dev/null; then
    # The tests require networking, which is disabled in libremakepkg
    # (for good reason).  But it's a bummer for these tests.
    # https://labs.parabola.nu/issues/3565
    return
  fi

  cd "$_pkgname-$pkgver"
  for tstfile in ./test.py tests/*; do
    echo "Running $tstfile..."
    case "$tstfile" in
      tests/test5.py) PYTHONPATH=. "$tstfile" parabola.nu;;
      *)              PYTHONPATH=. "$tstfile";;
    esac
  done
}

package() {
  _python_version=$(pacman -S --print-format='%v' python|cut -d- -f1|cut -d. -f1,2)
  depends=("python>=${_python_version}" "python<${_python_version%.*}.$(( ${_python_version##*.} + 1 ))")

  cd "$_pkgname-$pkgver"
  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/${pkgname#python-}-$pkgver.dist-info/licenses/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
