# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Felix Yan <felixonmars@archlinux.org>
# Contributor: Alexander Rødseth <rodseth@gmail.com>
# Contributor: Jan de Groot <jgc@archlinux.org>
# Contributor: Giorgio Lando <patroclo7@gmail.com>
# Contributor: Nicolas Quienot <niQo@aur>
# Contributor: Jesse Young <jesse.young@gmail.com>
# Contributor: Anton Eliasson <devel@antoneliasson.se>

pkgname=python-httplib2
pkgver=0.31.0
pkgrel=1
pkgdesc='Comprehensive HTTP client library, supporting many features'
arch=(any)
url='https://github.com/httplib2/httplib2'
license=(MIT)
depends=(
  ca-certificates
  python
  python-pyparsing
)
makedepends=(
  git
  python-build
  python-installer
  python-wheel
  python-setuptools
)
checkdepends=(
  flake8
  python-pytest-forked
  python-pytest-timeout
  python-pytest-xdist
  python-pytest-randomly
  python-cryptography
  python-pysocks
)
optdepends=(
  'python-pysocks: SOCKS proxy client support'
)
source=(
  "$pkgname::git+$url#tag=v$pkgver"
  use-system-certificates.patch
  remove-cov.patch
)
sha512sums=('3e97ca970b231388c7b29edd1aec7edde4b36266cec1f14c08ab84d6049a075d5cdabccddfc101075c75892db0a042936b298e02f3f8f28079d8a2a28a838f15'
            '99b4d3ad273f531a0ddf429015a59263e7e79754cd404580427cd7a0d8ad6455096ff49a3fbf60009448d066925b9a10255d0d4b3e75d2a9b6c88cbd6da5bb34'
            '1262401c70df5c5b1866067ce0bb23ed14ffdf5bce64807b1017a336a4125dbde9794673faba36bfb160b00edec9165b91e936a675b3f09b77f8db91cd4ae13f')
b2sums=('215cfafdc11b1303ec78df64918df765262bf28e6486b6b5b1f6f37b484c509ca0493758d1eebabb4de4eda9b1c6f1ef1dc3005e1d8b0cafd4b39bc6bab30b6f'
        '532f8208a57a2903d804ecda0e7f5076d300a3e1029c4effc29c6bb93683aaa283ae2f658c4be455d001e94afdcfbf331e06f19ac3a4c96db14210d185f5e904'
        'e8d7198de5baafb697ebc8730d4ab051240d80e3deb00a99b86966f69a9887f22ca2abc463189d1278857576b79de056f856fe74e5675e2f9f02364470170ed9')

prepare() {
  cd "$pkgname"

  # use system ca certificates
  patch -p1 -i "$srcdir/use-system-certificates.patch"
  rm -vf httplib2/cacerts.txt

  # do not use python-pytest-cov
  patch -p1 -i "$srcdir/remove-cov.patch"

  # patch requirements to allow newer versions of checkdepends
  sed -e 's/==/>=/' -i requirements-test.txt
}

build() {
  cd "$pkgname"

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

check() {
  cd "$pkgname"
  # test_client_cert_password_verified fails with cryptography 36 https://github.com/httplib2/httplib2/issues/221
  PYTHONPATH=build/lib pytest -k 'not test_client_cert_password_verified'
}

package() {
  cd "$pkgname"

  python setup.py install --root="$pkgdir" --optimize=1

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}

# vim:set ts=2 sw=2 et:
