# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=eventlet
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=0.31.0
pkgrel=1
pkgdesc="Highly concurrent networking library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://eventlet.net/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-greenlet"
         "${MINGW_PACKAGE_PREFIX}-python-monotonic"
         "${MINGW_PACKAGE_PREFIX}-python-dnspython"
         "${MINGW_PACKAGE_PREFIX}-python-six")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-psycopg2: non-blocking PostgreSQL support"
            "${MINGW_PACKAGE_PREFIX}-python-pyopenssl: non-blocking SSL support"
            "${MINGW_PACKAGE_PREFIX}-python-httplib2: non-blocking HTTP support"
            "${MINGW_PACKAGE_PREFIX}-python-pyzmq: non-blocking ZeroMQ support")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-psycopg2"
              "${MINGW_PACKAGE_PREFIX}-python-nose"
              "${MINGW_PACKAGE_PREFIX}-python-pyopenssl"
              "${MINGW_PACKAGE_PREFIX}-python-httplib2"
              "${MINGW_PACKAGE_PREFIX}-python-mock"
              "${MINGW_PACKAGE_PREFIX}-python-pyzmq")
options=('staticlibs' 'strip' '!debug')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/eventlet/eventlet/archive/v${pkgver}.tar.gz)
sha512sums=('50113061982f6d463058f838a13a2dfaca85ffa0a228241fe7560337d068de7b08c16d5e3c4f9b83b986d074da904669f295393b8cfd2d293c4cafdf7d401fd1')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  sed -r 's|(check_idle_cpu_usage\(.*,) .*\)|\1 0.8\)|g' \
      -i tests/*_test.py

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

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

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

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/nosetests -sv tests || warning "tests failed"
}

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}" --optimize=1 --skip-build

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