# Maintainer: Antoine Martin <totaam@xpra.org>

_realname=fido2
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.2.0
pkgrel=1
pkgdesc="For communicating with a FIDO device over USB as well as verifying attestation and assertion signatures (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://developers.yubico.com/python-fido2/'
msys2_repository_url='https://github.com/Yubico/python-fido2'
msys2_changelog_url='https://developers.yubico.com/python-fido2/Release_Notes.html'
msys2_references=(
  'archlinux: python-fido2'
  'gentoo: dev-python/fido2'
  'purl: pkg:pypi/fido2'
)
license=('spdx:BSD-2-Clause AND Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-cryptography"
         "${MINGW_PACKAGE_PREFIX}-libfido2")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-libfido2")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('0d8122e690096ad82afde42ac9d6433a4eeffda64084f36341ea02546b181dd1')

prepare() {
  cd "${_realname}-${pkgver}"
  sed -i \
    -e 's|requires = \["poetry-core"\]|requires = ["setuptools","wheel"]|' \
    -e 's|build-backend = "poetry.core.masonry.api"|build-backend = "setuptools.build_meta"|' \
    -e 's|, *email *= *"[^"]*"||g' \
    -e '/^readme *=/d' \
    pyproject.toml
}

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

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"
}
