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

_pkgname=httpcore
pkgname=python-httpcore
# https://github.com/encode/httpcore/blob/master/CHANGELOG.md
pkgver=1.0.9
pkgrel=2
pkgdesc="A minimal HTTP client"
arch=('any')
url="https://github.com/encode/${_pkgname}"
# https://github.com/encode/httpcore/blob/1.0.4/pyproject.toml#L9
license=('BSD-3-Clause')
depends=('python' 'python-h11' 'python-certifi')
optdepends=(
  'python-h2: for HTTP/2 support'
  'python-socksio: for SOCKS support'
  'python-anyio: for asyncio backend'
  'python-trio: for trio backend'
  # Used but not listed in pyproject.toml. Probably upstream relies on transitive dependency anyio -> sniffio
  'python-sniffio: for async support'
)
makedepends=('python-build' 'python-installer' 'python-hatchling' 'python-hatch-fancy-pypi-readme'
             'python-h2' 'python-socksio' 'python-trio' 'python-anyio' 'python-sniffio')
checkdepends=('python-pytest-httpbin' 'python-pytest-trio')
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/${pkgver}.tar.gz")
sha512sums=('0a1300d9c887dda66b4ac0739406daacd274c1137163b79dd8997a5928438c5b4b130a347e08016a2554bef73aad14225cd5786ff13e932e8d2fb48a4e7245ae')

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

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

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

    # raise open files limits, many tests will fail otherwise
    ulimit -S -n 4096

    # Overrides -Werror via -Wdefault, as the former often causes failures due to newer dependencies in Arch
    python -m pytest -Wdefault
}

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

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