# 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.22.0
pkgrel=4
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-cov'
  'python-pytest-forked'
  'python-pytest-timeout'
  'python-pytest-xdist'
  'python-pytest-randomly'
  'python-future'
  'python-cryptography'
  'python-six'
)
_commit=09eee8a81f552cbaa74f603f2dd9bcc3311ff6d7
source=(
  "$pkgname::git+$url#commit=$_commit"
  'use-system-certificates.patch'
)
sha512sums=('SKIP'
            '9699f17938703d1975417d244240d2df0062d309a1af91b33b438158e60d28ea3a38f439a774286a4090977f021d0ed3adc8c5c8c450bcbd4417649c735646f6')


pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # use system ca certificates
  patch -p1 -i "$srcdir/use-system-certificates.patch"
  rm -vf python{2,3}/httplib2/cacerts.txt

  # 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:
