# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: Jonas Witschel <diabonas@archlinux.org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Philipp A. <flying-sheep@web.de>

# Check if new updates break python-engineio

_pkgname=aiohttp
pkgname=python-aiohttp
_gitcommit=bf4edce5d6c967fa1d6a581b3aaab1bd2f5121cd
pkgver=3.9.3
pkgrel=1
pkgdesc='HTTP client/server for asyncio'
arch=('x86_64' 'aarch64')
url='https://aiohttp.readthedocs.io'
license=('Apache')
depends=(
  'python'
  'python-aiosignal'
  'python-attrs'
  'python-frozenlist'
  'python-multidict'
  'python-yarl'
)
makedepends=(
  'cython'
  'git'
  'npm'
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
)
checkdepends=(
  'gunicorn'
  'python-aiodns'
  'python-brotli'
  'python-freezegun'
  'python-proxy.py'
  'python-pytest'
  'python-pytest-mock'
  'python-pytest-xdist'
  'python-re-assert'
  'python-time-machine'
  'python-trustme'
  'python-uvloop'
)
optdepends=(
  'gunicorn: to deploy using Gunicorn'
  'python-aiodns: for fast DNS resolving'
  'python-brotli: for Brotli transfer-encodings support'
)
source=(
  "${pkgname}::git+https://github.com/aio-libs/aiohttp#commit=${_gitcommit}"
  'backport-fix-failing-test.patch'
  git+https://github.com/nodejs/llhttp.git
)
sha512sums=('SKIP'
            'SKIP'
            'SKIP')

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

prepare() {
  cd ${pkgname}
  patch -p1 -i "$srcdir/backport-fix-failing-test.patch"
  git submodule init
  git config submodule."vendor/llhttp".url "${srcdir}/llhttp"
  git -c protocol.file.allow=always submodule update --recursive
  sed 's|.install-cython ||' -i Makefile

  # This test calls the Python interpreter, we need to make sure that the path
  # for the C extensions is correct there as well
  sed -i "s/import {import_path!s}/import sys; sys.path.insert(0, '{os.environ['PYTHONPATH']}'); &/" \
      tests/test_circular_imports.py

  # Remove coverage testing
  sed -i '/--cov=/d' setup.cfg
}

build() {
  cd ${pkgname}
  make generate-llhttp cythonize
  python -m build --wheel --no-isolation
}

check() {
  cd ${pkgname}
  local _python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
  mv tests/autobahn/test_autobahn.py{,.bak} # Docker tests
  PYTHONPATH="$PWD/build/lib.linux-$CARCH-cpython-${_python_version}" pytest
  mv tests/autobahn/test_autobahn.py{.bak,}
}

package() {
  cd ${pkgname}
  python -m installer --destdir="$pkgdir" dist/*.whl
}

# vim: ts=2 sw=2 et:
