# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Maintainer: Carl Smedstad <carsme@archlinux.org>

pkgname=python-blosc2
pkgver=4.1.2
pkgrel=1
pkgdesc='Wrapper for the blosc2 compressor'
arch=(x86_64 aarch64)
url='https://github.com/Blosc/python-blosc2'
license=(BSD-3-Clause)
depends=(
  blosc2
  glibc
  python
  python-msgpack
  python-ndindex
  python-numexpr
  python-numpy
  python-requests
)
makedepends=(
  cmake
  cython
  git
  ninja
  python-build
  python-installer
  python-scikit-build-core
  python-setuptools
)
checkdepends=(
  python-psutil
  python-pytest
  python-pytorch
)
source=("$pkgname::git+$url#tag=v$pkgver")
sha512sums=('4e8798e608177aa7517153293df54e538d7619d3022c5b77729df1fe2d40891a74f921fd18a3c03769cbd58e20a3aecee66bda232748aae734e9dc1b51a599d3')
b2sums=('0eedb0dfa52d7f4f7b60a9315c531b798091edfbfcb7865219dcd77f63e7630999b2ef7af77935bad71818b92883bbea7ffa7b5a80259e56cad551268b1e1a0b')

build() {
  cd $pkgname
  export CMAKE_ARGS="-DUSE_SYSTEM_BLOSC2=ON"
  python -m build --wheel --no-isolation
}

check() {
  cd $pkgname
  python -m venv venv-test --system-site-packages
  ./venv-test/bin/python -m installer dist/*.whl
  # Deselect tests failing since v3.4.0, not sure why
  # test_expand_dims: sys.getrefcount() behavior changed in Python 3.14
  ./venv-test/bin/python -m pytest \
    --deselect tests/ndarray/test_resize.py::test_expand_dims \
    --deselect tests/ndarray/test_lazyexpr.py::test_broadcasting \
    --deselect tests/ndarray/test_lazyexpr.py::test_chain_expressions \
    --deselect tests/ndarray/test_lazyexpr.py::test_chain_persistentexpressions \
    --deselect tests/ndarray/test_reductions.py::test_broadcast_params \
    --deselect tests/ndarray/test_reductions.py::test_fast_path \
    --deselect tests/ndarray/test_reductions.py::test_save_version1 \
    --deselect tests/ndarray/test_reductions.py::test_save_version2 \
    --deselect tests/ndarray/test_reductions.py::test_save_version3 \
    --deselect tests/ndarray/test_reductions.py::test_save_version4
}

package() {
  cd $pkgname

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

  # why are these files there?
  (
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  cd "$pkgdir$site_packages"
  rm -vrf include lib share
  )

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