# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=hypercorn
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.18.0
pkgrel=1
pkgdesc='An ASGI Server based on Hyper libraries and inspired by Gunicorn (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://hypercorn.readthedocs.io/'
msys2_repository_url='https://github.com/pgjones/hypercorn'
msys2_changelog_url='https://github.com/pgjones/hypercorn/blob/main/CHANGELOG.rst'
msys2_references=(
  'archlinux: hypercorn'
  'gentoo: dev-python/hypercorn'
  'purl: pkg:pypi/hypercorn'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-h11"
         "${MINGW_PACKAGE_PREFIX}-python-h2"
         "${MINGW_PACKAGE_PREFIX}-python-priority"
         "${MINGW_PACKAGE_PREFIX}-python-toml"
         "${MINGW_PACKAGE_PREFIX}-python-typing_extensions"
         "${MINGW_PACKAGE_PREFIX}-python-wsproto")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-pdm-backend")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('d63267548939c46b0247dc8e5b45a9947590e35e64ee73a23c074aa3cf88e9da')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

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 "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
