# Maintainer: Xeonacid <h.dwwwwww@gmail.com>

_name=coincurve
pkgname=python-${_name}
pkgver=21.0.0
pkgrel=2
pkgdesc="Cross-platform Python bindings for libsecp256k1"
arch=(x86_64)
url="https://github.com/ofek/${_name}"
license=(Apache-2.0 MIT)
depends=(glibc python python-asn1crypto python-cffi)
makedepends=(git python-build python-installer python-setuptools python-wheel python-hatchling python-scikit-build-core)
checkdepends=(python-pytest python-pytest-benchmark)
source=("git+$url.git#tag=v$pkgver"
        Add-get_cffi_distribution_license_files.patch)
sha512sums=('a4e60f4958536ef8f25b7d23e51984e1bba13aec4985fa5f2f8cac1bd31f147fb36a4400e1c9865949f548be214188091a8dd0ccd7687f4cc7055a3a3cbe03ec'
            '4344bd6ec13257f2ef58f11345b26a1c851fb1c650fe5c9ec5b23f9f577e1468d0ab2607dbd33d9b3dafea3bc7ccf7f3078b89c62ec78da5eba8007925969b2c')

prepare() {
  cd $_name
  # Fix RuntimeError: Expected exactly one LICENSE file in cffi distribution, got 0
  patch -Np1 -i ../Add-get_cffi_distribution_license_files.patch
}

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

check(){
  cd $_name
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest -vv tests/
}

package() {
  cd $_name
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm 644 LICENSE-MIT -t "$pkgdir/usr/share/licenses/$pkgname"
  install -Dm 644 LICENSE-APACHE -t "$pkgdir/usr/share/licenses/$pkgname"
  install -dm 755 "$pkgdir/usr/share/doc/$pkgname"
  cp -r docs "$pkgdir/usr/share/doc/$pkgname"
  install -Dm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname"
}
