# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Ralf Schmitt <ralf@systemexit.de>

pkgname=python-greenlet
pkgver=3.1.1
pkgrel=1
pkgdesc="Lightweight in-process concurrent programming"
license=("MIT")
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://pypi.org/project/greenlet/"
depends=('python')
makedepends=('python-build' 'python-installer' 'python-setuptools'
             'python-wheel')
checkdepends=('python-objgraph' 'python-psutil')
source=("https://files.pythonhosted.org/packages/source/g/greenlet/greenlet-${pkgver}.tar.gz")
sha512sums=('915a6e22c20b235de472c61c7bc4cb60a08b79e29127c4fb817c362cee37f589bc362f12ed31bdc7dda91f49976d4e2784c8d13202bf598156a0aacacdb7f6fb')

build() {
    cd greenlet-$pkgver
    case "${CARCH}" in
      powerpc64*) export CFLAGS="-O2 -pipe" ;;
    esac
    python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
    cd greenlet-$pkgver
    local _python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
    PYTHONPATH="$PWD/build/lib.linux-$CARCH-cpython-$_python_version" python -m unittest discover -v greenlet.tests
}

package() {
    cd greenlet-$pkgver
    python -m installer --destdir="$pkgdir" dist/*.whl
    rm -rf "$pkgdir"/usr/lib/python*/site-packages/greenlet/tests
    install -Dm644 LICENSE.PSF -t "$pkgdir"/usr/share/licenses/$pkgname/
}
