# Maintainer: Luke T. Shumaker <lukeshu@parabola.nu>
# Maintainer (aur): Hao Zhang <hao at hao-zhang com>
# Contributor (aur): Rich Li <rich at dranek com>
# Contributor (aur): Samed Beyribey <ras0ir AT eventualis DOT org>
#
# Rationale: Dependency of pcr/spf-engine

pkgname=python-pyspf
_pkgname=${pkgname#python-}
pkgver=2.0.14.r29.g1042e9e
# We go past the latest stable release to get Python 3.13 fixes and
# the fix for https://github.com/sdgathman/pyspf/issues/24.
_commit=1042e9e15dd29047dc9b0a1bb77437e2fd81e775
pkgrel=1
pkgdesc="Python implementation of the Sender Policy Framework (SPF) protocol"
arch=('any')
url="https://github.com/sdgathman/pyspf/"
license=('PSF-2.0')

makedepends=('git' 'python-build' 'python-installer' 'python-wheel' 'python-setuptools')
depends=('python-dnspython')
checkdepends=('python-yaml' 'python-authres')
optdepends=('python-authres: Return RFC 5451 Authentication Results headers')

source=("git+https://github.com/sdgathman/pyspf.git#commit=${_commit}")
sha256sums=('afa71f146a448fb382369e1ac37d7cae867365661c23bbb1ec4c0da495d89d1d')

pkgver() {
  cd "$_pkgname"
  git describe --long --tags | sed -E 's/^pyspf-(.*)-([0-9]+)-g/\1.r\2.g/'
}

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

check() {
  cd "$_pkgname/test"
  PYTHONPATH=../build/lib python testspf.py
}

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"
  python -m installer --destdir="$pkgdir" dist/*.whl
}
