# Maintainer: David Runge <dvzrv@archlinux.org>

_name=cytoolz
pkgname=python-cytoolz
pkgver=0.12.3
pkgrel=2
pkgdesc="Cython implementation of Toolz: High performance functional utilities"
arch=(x86_64 aarch64)
url="https://github.com/pytoolz/cytoolz/"
license=(BSD-3-Clause)
depends=(
  glibc
  python
  python-toolz
)
makedepends=(
  cython
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(python-pytest)
source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz
        fix-test-inspect-wrapped-property.patch
)
sha512sums=('b3c46182b1d93b4e862e8d37e7e49fd44126e7ce503b9a25f7d78ff79ee9eac938bf47a63fda6ff6adbb660efedf0eb07810fbc2e91d7a471cb0167bb7ef0ad6'
            'ebb39fd6abf097083560980b63cdc18a406013dd8f013072c18d95335e326698cb6164111aa03a9bc38b4d42c1234510bf10b498a0674c808b47cbaea0aa4940')
b2sums=('ad1b4474a5c5f954cabf38c447982fb44f4c57fb5637e827876fe3bf4fad7c947fb926087294d06769944a4d67d7cfea3e7f7cc68162ebd69cc9746a80fc5aad'
        '9678c3b145c4463065f9dc1e3bc8db78ebbcc0465d160849ba84a91494552225db6cfb5403a106abf0f75bf89e32696629861ff2959d4d2a617ba8cd060a80c0')

prepare() {
  cd $_name-$pkgver
  patch -Np1 < "$srcdir/fix-test-inspect-wrapped-property.patch"
}

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

check() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"
  pytest -vv test_dir/$_site_packages
}

package() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 README.rst -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -vDm 644 LICENSE.txt -t "${pkgdir}/usr/share/licenses/${pkgname}"
  rm -frv "$pkgdir/$_site_packages/$_name/tests"
}
