# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>

pkgname=python-pycryptodome
pkgver=3.20.0
pkgrel=2
license=('BSD')
arch=('x86_64' 'aarch64')
pkgdesc="Collection of cryptographic algorithms and protocols, implemented for use from Python 3."
url='https://www.pycryptodome.org/'
depends=('python' 'gmp')
makedepends=('gmp' 'python-'{build,installer,wheel} 'python-setuptools')
conflicts=('python-crypto')
provides=('python-crypto')
replaces=('python-crypto')
source=("pycryptodome-$pkgver.tar.gz::https://github.com/Legrandin/pycryptodome/archive/v$pkgver.tar.gz")
sha512sums=('0d65ccd93f9f78548c04aa3af01cb65b6a39e81bb3dfa4bb08acc5a5a731b17f9c5b07a1d1780739b3f358402a3596b04e446fc7b39345a4c6f03fd5a2de7ff9')

build() {
  cd pycryptodome-$pkgver
  python -m build -wn

  cd test_vectors
  python -m build -wn
}

check() {
  cd pycryptodome-$pkgver
  python -m installer -d tmpinstall dist/*.whl
  python -m installer -d tmpinstall test_vectors/dist/*.whl
  local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
  PYTHONPATH="$PWD/tmpinstall/usr/lib/python${python_version}/site-packages" python -m Crypto.SelfTest
}

package() {
  cd pycryptodome-$pkgver
  python -m installer -d "$pkgdir" dist/*.whl
  install -Dm644 LICENSE.rst -t "$pkgdir"/usr/share/licenses/$pkgname/

  rm -r "$pkgdir"/usr/lib/python3.*/site-packages/Crypto/SelfTest/
}
