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

_realname=httpx
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.27.0
pkgrel=2
pkgdesc="A next generation HTTP client for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.python-httpx.org/'
msys2_repository_url='https://github.com/encode/httpx'
msys2_references=(
  "cpe: cpe:/a:encode:httpx"
  "pypi: httpx"
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-certifi"
         "${MINGW_PACKAGE_PREFIX}-python-httpcore"
         "${MINGW_PACKAGE_PREFIX}-python-idna"
         "${MINGW_PACKAGE_PREFIX}-python-sniffio"
         "${MINGW_PACKAGE_PREFIX}-python-anyio")
optdepends=(#"${MINGW_PACKAGE_PREFIX}-python-brotli: for brotli response decompression"
            #"${MINGW_PACKAGE_PREFIX}-python-brotlicffi: for brotli response decompression"
            "${MINGW_PACKAGE_PREFIX}-python-h2: for HTTP/2 support"
            #"${MINGW_PACKAGE_PREFIX}-python-socksio: for SOCKS proxy support"
            #"${MINGW_PACKAGE_PREFIX}-python-trio: for trio backend"
            "${MINGW_PACKAGE_PREFIX}-python-click: command line client support"
            "${MINGW_PACKAGE_PREFIX}-python-rich: command line client support"
            "${MINGW_PACKAGE_PREFIX}-python-pygments: command line client 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")
options=(!strip)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('a0cb88a46f32dc874e04ee956e4c2764aba2aa228f650b06788ba6bda2962ab5')

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() {
  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"
}
