# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=aiohttp
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.7.4.post0
_gitcommit=184274d9b28bbfa06ac60e48bf286a761c6a6cb0
pkgrel=1
pkgdesc='HTTP client/server for asyncio (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://aiohttp.readthedocs.io/"
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python-async-timeout"
"${MINGW_PACKAGE_PREFIX}-python-attrs"
"${MINGW_PACKAGE_PREFIX}-python-chardet"
"${MINGW_PACKAGE_PREFIX}-python-yarl")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "${MINGW_PACKAGE_PREFIX}-cython" "git")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-freezegun"
"${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
"${MINGW_PACKAGE_PREFIX}-python-pytest-cov"
"${MINGW_PACKAGE_PREFIX}-python-pytest-forked"
"${MINGW_PACKAGE_PREFIX}-python-pytest-mock"
"${MINGW_PACKAGE_PREFIX}-python-pytest-timeout"
"${MINGW_PACKAGE_PREFIX}-python-pytest-xdist"
"${MINGW_PACKAGE_PREFIX}-python-trustme"
"${MINGW_PACKAGE_PREFIX}-python-async_generator"
"${MINGW_PACKAGE_PREFIX}-python-brotli")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-brotli: for Brotli transfer-encodings support")
source=("git+https://github.com/aio-libs/aiohttp#commit=${_gitcommit}"
        "git+https://github.com/nodejs/http-parser"
		"python-aiohttp-release-resources-pytest.patch"
        "python-aiohttp-brotli.patch")
sha256sums=('SKIP'
            'SKIP'
            '68eac724a7ed691de5f242b062e80f4070e87dbc13739d10d4ae9602832fc026'
            '79b55f820809d7441ebe4124e101511f3e8b6ee20d7eeeb7da7c7ed49d448c9e')

pkgver() {
  cd $srcdir/${_realname}
  git describe --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {  
  cd "$srcdir/${_realname}"
  git submodule init
  git config submodule."vendor/http-parser".url "${srcdir}/http-parser"
  git submodule update --recursive
  # fix tests
  git revert -n 942c1b801f0ce4b5cd0103be58eb0359edf698a2
  cd ..
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}" "python-build-${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  patch -p1 -i ../python-aiohttp-release-resources-pytest.patch
  patch -p1 -i ../python-aiohttp-brotli.patch
  sed 's|.install-cython ||' -i Makefile
}

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

check() {
  cd "${srcdir}/python-build-${CARCH}"
  #${MINGW_PREFIX}/bin/python setup.py test || 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.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
