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

_realname=requests
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.21.0
pkgrel=1
pkgdesc="Requests is the only Non-GMO HTTP library for Python, safe for human consumption. (mingw-w64)"
arch=('any')
license=('Apache')
url="http://python-requests.org/"
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-chardet"
             "${MINGW_PACKAGE_PREFIX}-python2-chardet"
             "${MINGW_PACKAGE_PREFIX}-python3-urllib3"
             "${MINGW_PACKAGE_PREFIX}-python2-urllib3"
             "${MINGW_PACKAGE_PREFIX}-python3-idna" 
             "${MINGW_PACKAGE_PREFIX}-python2-idna")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python3-pytest-httpbin"
              "${MINGW_PACKAGE_PREFIX}-python2-pytest-httpbin"
              "${MINGW_PACKAGE_PREFIX}-python3-pytest-mock"
              "${MINGW_PACKAGE_PREFIX}-python2-pytest-mock"
              "${MINGW_PACKAGE_PREFIX}-python3-pysocks"
              "${MINGW_PACKAGE_PREFIX}-python2-pysocks")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/kennethreitz/requests/archive/v${pkgver}.tar.gz")
sha256sums=('9f9a50b5f64f4569704b9c5e618b957109e3486256453c9016c6dbfa10570761')

prepare() {
  cd "$srcdir"
  for builddir in python{2,3}-build; do  
    rm -rf $builddir | true
    cp -r "${_realname}-${pkgver}" "${builddir}"
  done
}

build() {  
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

package_python3-requests() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-urllib3" 
           "${MINGW_PACKAGE_PREFIX}-python3-chardet" 
           "${MINGW_PACKAGE_PREFIX}-python3-idna")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python3-pysocks: SOCKS proxy support")

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

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

package_python2-requests() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-urllib3"
           "${MINGW_PACKAGE_PREFIX}-python2-chardet"
           "${MINGW_PACKAGE_PREFIX}-python2-idna")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python2-ndg-httpsclient: HTTPS requests with SNI support"
              "${MINGW_PACKAGE_PREFIX}-python2-grequests: asynchronous requests with gevent"
              "${MINGW_PACKAGE_PREFIX}-python2-pysocks: SOCKS proxy support")

  cd "${srcdir}/python3-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

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

package_mingw-w64-i686-python2-requests() {
  package_python2-requests
}

package_mingw-w64-i686-python3-requests() {
  package_python3-requests
}

package_mingw-w64-x86_64-python2-requests() {
  package_python2-requests
}

package_mingw-w64-x86_64-python3-requests() {
  package_python3-requests
}
