# Contributor: Alethea Rose <alethea@alethearose.com>

_realname=requests
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.25.1
pkgrel=2
pkgdesc="Requests is the only Non-GMO HTTP library for Python, safe for human consumption (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('Apache')
url="https://2.python-requests.org"
depends=("${MINGW_PACKAGE_PREFIX}-python-urllib3"
         "${MINGW_PACKAGE_PREFIX}-python-chardet"
         "${MINGW_PACKAGE_PREFIX}-python-idna")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-httpbin"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-mock"
              "${MINGW_PACKAGE_PREFIX}-python-pysocks")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pysocks: SOCKS proxy support")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/kennethreitz/requests/archive/v${pkgver}.tar.gz"
        "0001-support-newer-idna-5711.patch")
sha256sums=('03b192fad682a33964df331d35f90918b1940c89f6c5bcb10060be688ba50315'
            'a9ff911323b86162560898684c6a1a7c1e55de1f63b6661ae5b1038f66b7189d')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  # https://github.com/psf/requests/pull/5711
  patch -Np1 -i "${srcdir}/0001-support-newer-idna-5711.patch"

  cd "${srcdir}"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
