# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Thomas Dziedzic < gostrc at gmail >
# Contributor: Angel 'angvp' Velasquez <angvp[at]archlinux.com.ve>
# Contributor: Ray Rashif <schiv@archlinux.org>
# Contributor: Douglas Soares de Andrade <dsa@aur.archlinux.org>
# Contributor: Bodor Dávid Gábor <david.gabor.bodor@gmail.com>
# Contributor: Andrzej Giniewicz <gginiu@gmail.com>

_name=scipy
pkgname=python-scipy
pkgver=1.15.1
pkgrel=1
pkgdesc='Open-source software for mathematics, science, and engineering'
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url='https://www.scipy.org/'
license=(BSD-3-Clause)
depends=(blas
         gcc-libs
         glibc
         lapack
         python
         python-numpy
         python-platformdirs
         python-pooch)
provides=(scipy)
makedepends=(boost
             cython
             gcc-fortran
             git
             meson-python
             pybind11
             python-build
             python-installer
             python-pythran)
checkdepends=(python-hypothesis
              python-pytest)
optdepends=('python-pillow: for image saving module')
source=(git+https://github.com/scipy/scipy#tag=v$pkgver
        git+https://github.com/data-apis/array-api-compat
        git+https://github.com/boostorg/math
        git+https://github.com/cobyqa/cobyqa
        git+https://github.com/scipy/pocketfft
        git+https://github.com/scipy/unuran)
sha256sums=('6a88925a552f951461adc9e01b4a1701d207976be2688e4fb26bea514bc79e64'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP')
options=(!lto) # crashes with numpy 2.0

prepare() {
  cd $_name
  git submodule init
  git submodule set-url scipy/_lib/array_api_compat "$srcdir"/array-api-compat
  git submodule set-url scipy/_lib/boost_math "$srcdir"/math
  git submodule set-url scipy/_lib/cobyqa "$srcdir"/cobyqa
  git submodule set-url scipy/_lib/pocketfft "$srcdir"/pocketfft
  git submodule set-url scipy/_lib/unuran "$srcdir"/unuran
  git -c protocol.file.allow=always submodule update
}

build() {
  cd $_name
  python -m build --wheel --no-isolation --skip-dependency-check \
    -C setup-args=-Dblas=blas \
    -C setup-args=-Dlapack=lapack
}

check() {
  cd $_name
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  cd test-env
  bin/python -c "from scipy import test; test('full')"
}

package() {
  cd $_name
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname
}
