# Maintainer: Bruno Pagani <archange@archlinux.org>
# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Andrzej Giniewicz <gginiu@gmail.com>

pkgname=python-blosc
pkgver=1.11.2
pkgrel=2
pkgdesc='Python wrapper for the extremely fast Blosc compression library'
arch=('x86_64' 'aarch64')
url='https://www.blosc.org/python-blosc/python-blosc.html'
license=('BSD-3-Clause')
depends=('python' 'blosc')
makedepends=(
  'cmake'
  'ninja'
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
  'python-scikit-build'
  'python-py-cpuinfo'
)
checkdepends=('python-numpy' 'python-psutil')
optdepends=('python-numpy: for tests and benchmarks')
source=("https://github.com/Blosc/python-blosc/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('56a53828669ac9d1452b247b8aad6bdfcb71ecffe9b8c7723e4405825704506946f150f54633b7e0886160255e5619c698b97847963c909e14c97808c04f39ab')
b2sums=('79176961221a2dcdf389165b3ed0e629201605f806aca3e1ada1dd9b35c1acf13ea7fa6692a762f5e31270df327751642256a1c5bafb14fbed48ef69c6b9745c')

build() {
  cd "${pkgname}-${pkgver}"

  # AVX2 disabled because Arch does not have x86_64_v3 yet.
  # Snappy is also disabled by default for compatability with non-C++ systems.
  export CMAKE_ARGS="\
    -DCMAKE_C_FLAGS_INIT=-DNDEBUG \
    -DCMAKE_BUILD_TYPE=None \
    -DUSE_SYSTEM_BLOSC=ON \
    -DDEACTIVATE_SNAPPY=OFF \
    -DDEACTIVATE_AVX2=ON"

  # skip unnecessary dependencies (ninja, cmake, etc)
  python -m build --wheel --no-isolation --skip-dependency-check
}

check() {
  cd "${pkgname}-${pkgver}"

  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m blosc.test
}

package() {
  cd "${pkgname}-${pkgver}"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE.txt
}
