# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pycryptodome
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.23.0
pkgrel=1
pkgdesc="Collection of cryptographic algorithms and protocols, implemented for use from Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.pycryptodome.org/"
msys2_repository_url='https://github.com/Legrandin/pycryptodome/'
msys2_references=(
  'archlinux: python-pycryptodome'
  'purl: pkg:pypi/pycryptodome'
)
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-gmp"
         "${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
source=("https://github.com/Legrandin/pycryptodome/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('5a905f0f4237b79aefee47f3e04568db2ecb70c55dd7cb118974c5260aa9e285')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE.rst "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.rst"
}
