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

_realname=httpcore
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.0.8
pkgrel=1
pkgdesc="A minimal HTTP client (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.encode.io/httpcore/'
msys2_repository_url='https://github.com/encode/httpcore'
msys2_references=(
  "purl: pkg:pypi/httpcore"
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-certifi"
         "${MINGW_PACKAGE_PREFIX}-python-h11")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-h2: for HTTP/2 support"
            #"${MINGW_PACKAGE_PREFIX}-python-socksio: for SOCKS support"
            "${MINGW_PACKAGE_PREFIX}-python-anyio: for asyncio backend"
            #"${MINGW_PACKAGE_PREFIX}-python-trio: for trio backend"
            # Used but not listed in pyproject.toml. Probably upstream relies on transitive dependency anyio -> sniffio
            "${MINGW_PACKAGE_PREFIX}-python-sniffio: for async support")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-hatchling"
             "${MINGW_PACKAGE_PREFIX}-python-hatch-fancy-pypi-readme")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('86e94505ed24ea06514883fd44d2bc02d90e77e7979c8eb71b90f41d364a1bad')

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"
}
