# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=urllib3
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.6.2
pkgrel=1
pkgdesc="HTTP library with thread-safe connection pooling and file post support (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://urllib3.readthedocs.io/'
msys2_repository_url='https://github.com/urllib3/urllib3'
msys2_references=(
  'archlinux: python-urllib3'
  'purl: pkg:pypi/urllib3'
  "cpe: cpe:/a:python:urllib3"
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-hatchling"
             "${MINGW_PACKAGE_PREFIX}-python-hatch-vcs")
if [[ ${CARCH} != i686 ]]; then
optdepends=("${MINGW_PACKAGE_PREFIX}-python-brotli: Brotli support"
            "${MINGW_PACKAGE_PREFIX}-python-zstandard: Zstandard support"
            "${MINGW_PACKAGE_PREFIX}-python-h2: HTTP/2 support"
            "${MINGW_PACKAGE_PREFIX}-python-pysocks: SOCKS support")
fi
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-brotli"
              "${MINGW_PACKAGE_PREFIX}-python-cryptography"
              "${MINGW_PACKAGE_PREFIX}-python-idna"
              "${MINGW_PACKAGE_PREFIX}-python-pyopenssl"
              "${MINGW_PACKAGE_PREFIX}-python-pysocks"
              "${MINGW_PACKAGE_PREFIX}-python-coverage"
              "${MINGW_PACKAGE_PREFIX}-python-dateutil"
              "${MINGW_PACKAGE_PREFIX}-python-flaky"
              "${MINGW_PACKAGE_PREFIX}-python-mock"
              "${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-timeout"
              "${MINGW_PACKAGE_PREFIX}-python-tornado"
              "${MINGW_PACKAGE_PREFIX}-python-h2"
              "${MINGW_PACKAGE_PREFIX}-python-zstandard"
              "${MINGW_PACKAGE_PREFIX}-python-trustme")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('016f9c98bb7e98085cb2b4b17b87d2c702975664e4f060c6532e64d1c1a5e797')

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