# Maintainer: Alexey Pavlov <alexpux@gmail.om>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=httplib2
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.22.0
pkgrel=4
pkgdesc="Comprehensive HTTP client library, supporting many features (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/httplib2/httplib2"
msys2_references=(
  "cpe: cpe:/a:httplib2_project:httplib2"
  "purl: pkg:pypi/httplib2"
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-certifi"
         "${MINGW_PACKAGE_PREFIX}-ca-certificates"
         "${MINGW_PACKAGE_PREFIX}-python-pyparsing")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz
        cert.patch)
sha256sums=('d7a10bc5ef5ab08322488bde8c726eeee5c8618723fdb399597ec58f3d82df81'
            '3503625ade773c17c9c44f4017aec634ff03db0073eb3ec11e6882a466d7aae6')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Patch, ref FS#40179
  patch -p1 -i "${srcdir}/cert.patch"
}

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/python-${_realname}/LICENSE
}
