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

_realname=starlette
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
epoch=1
pkgver=0.50.0
pkgrel=1
pkgdesc="The little ASGI framework that shines (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/encode/starlette'
msys2_references=(
  'archlinux: python-starlette'
  'gentoo: dev-python/starlette'
  'purl: pkg:pypi/starlette'
  "cpe: cpe:2.3:a:encode:starlette"
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-anyio")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-hatchling")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-itsdangerous: for session middleware support"
            "${MINGW_PACKAGE_PREFIX}-python-jinja: for jinja templates"
            "${MINGW_PACKAGE_PREFIX}-python-python-multipart: for form parsing"
            "${MINGW_PACKAGE_PREFIX}-python-yaml: for schema generator"
            "${MINGW_PACKAGE_PREFIX}-python-httpx: for test client")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('a2a17b22203254bcbc2e1f926d2d55f3f9497f769416b3190768befe598fa3ca')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"

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

package() {
  msg "Python install for ${MSYSTEM}"
  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.md "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.md"
}
