# Maintainer: Chih-Hsuan Yen <yan12125@archlinux.org>
# Maintainer: Robin Candau <antiz@archlinux.org>
# Contributor: Eli Schwartz <eschwartz@archlinux.org>

_pkgname=httpx
pkgname=python-httpx
# https://github.com/encode/httpx/blob/master/CHANGELOG.md
pkgver=0.28.1
pkgrel=3
pkgdesc="A next generation HTTP client for Python"
arch=('any')
url="https://github.com/encode/${_pkgname}"
# https://github.com/encode/httpx/blob/0.27.0/pyproject.toml#L8
license=('BSD-3-Clause')
depends=('python' 'python-certifi' 'python-httpcore' 'python-idna' 'python-sniffio'
         # Not directly used, but declared as anyio is no longer a hard dependency of newer httpcore
         # https://github.com/encode/httpx/pull/2885
         'python-anyio')
optdepends=(
  'python-brotli: for brotli response decompression'
  'python-brotlicffi: for brotli response decompression'
  'python-zstandard: for zstd response decompression'
  'python-h2: HTTP/2 support'
  'python-socksio: SOCKS proxy support'
  'python-click: command line client support'
  'python-rich: command line client support'
  'python-pygments: command line client support'
  'python-trio: alternative async library'
)
makedepends=('python-build' 'python-installer' 'python-hatchling' 'python-hatch-fancy-pypi-readme'
             'python-pygments')
checkdepends=('python-pytest-asyncio' 'python-pytest-trio' 'python-brotli' 'python-brotlicffi' 'python-h2' 'python-trustme' 'uvicorn' 'python-socksio'
              'python-rich' 'python-chardet' 'python-zstandard')
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/${pkgver}.tar.gz"
        "uvicorn-test-server-use-h11.diff")
sha512sums=('5571957a3516533f1c1e76f311316811f6365e192d19ebae10c9ab0d0c4094d811063fd2be2995f3b6a41d6899a7882f27265badecf238a4f7903f976136d3ba'
            'd3e6a9df365aff5e4e7b724469672c6da9c7e95cc5d79339ebd1ea249236802d81b8792efb0826f89747424fa1bef20d4965ddb75b3b67e9cd320b5fcc738f18')
b2sums=('76c24a3b3618798d5b65aaaa87ee583f9debf8cb7866204a3e12c151179d9f69a6ad23198c9ee7df61058f73b6ca84f453c3bced25a60f583d7b3ad7681839bb'
        'f7fc5aa67d59dfbf544ea2668a5df6449d1cb30f5adf1433d92ebbc0fd10d46fec592f1befe829e126d72240666b9c3ea1f69a9f2cca6f3f4e135a7e454be25d')

prepare() {
  cd ${_pkgname}-${pkgver}

  # fix tests
  patch -Np1 -i ../uvicorn-test-server-use-h11.diff

  # disable -Werror, which often causes failures due to newer dependencies in Arch
  sed -i '/"error",/d' pyproject.toml
}

build() {
  cd ${_pkgname}-${pkgver}

  python -m build --wheel --no-isolation
}

check() {
  cd ${_pkgname}-${pkgver}

  pytest
}

package() {
  cd ${_pkgname}-${pkgver}

  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm644 LICENSE.md "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE.md

  # Package the test suite as it is used to test python-httpx-aiohttp.
  install -vDm644 -t "${pkgdir}/usr/share/${pkgname}" pyproject.toml
  cp -va -t "${pkgdir}/usr/share/${pkgname}" tests
}
