# Maintainer: Johannes Löthberg <johannes@kyriasis.com>
# Maintainer: Carl Smedstad <carsme@archlinux.org>

pkgname=python-hiredis
_pkgname=hiredis-py
pkgver=3.3.0
pkgrel=1
pkgdesc='Non-blocking redis client for python'
arch=('x86_64' 'aarch64')
url='https://pypi.org/project/hiredis/'
license=('MIT')
depends=(
  'glibc'
  'hiredis'
  'python'
)
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
)
checkdepends=('python-pytest')
source=(
  "git+https://github.com/redis/hiredis-py.git#tag=v$pkgver"
  "$pkgname-use-system-hiredis.patch"
)
sha256sums=('72697c1bc6cb458cc6df879b2b3c43d346b75bf29c49681e30daf6f38efc58fd'
            'e7a8f559ec5b580b3f60c792e0a056c80071bbcf2a2ec5912b00f90eef9b1de7')

prepare() {
  cd $_pkgname
  patch -Np1 < ../$pkgname-use-system-hiredis.patch
}

build() {
  cd $_pkgname
  python -m build --wheel --no-isolation
}

check() {
  cd $_pkgname
  python -m installer --destdir=tmp_install dist/*.whl
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  PYTHONPATH="$PWD/tmp_install/$site_packages" pytest
}

package() {
  cd $_pkgname
  python -m installer -d "$pkgdir" dist/*.whl
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
