# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>
# Contributor: Miloš Komarčević <miloskomarcevic@aim.com>

_pyname=scikit_image
_realname=scikit-image
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.26.0
pkgrel=2
pkgdesc='Image processing routines for SciPy (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://scikit-image.org/"
msys2_repository_url="https://github.com/scikit-image/scikit-image"
msys2_references=(
  'purl: pkg:pypi/scikit-image'
)
license=('spdx:BSD-3-Clause AND BSD-2-Clause AND MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-matplotlib>=3.5"
  "${MINGW_PACKAGE_PREFIX}-python-scipy>=1.11.4"
  "${MINGW_PACKAGE_PREFIX}-python-pywavelets>=1.1.1"
  "${MINGW_PACKAGE_PREFIX}-python-numpy>1.24"
  "${MINGW_PACKAGE_PREFIX}-python-networkx>=3.0"
  "${MINGW_PACKAGE_PREFIX}-python-imageio>=2.33"
  "${MINGW_PACKAGE_PREFIX}-python-tifffile>=2022.8.12"
  "${MINGW_PACKAGE_PREFIX}-python-packaging>=21"
  "${MINGW_PACKAGE_PREFIX}-python-pillow>=10.1"
  "${MINGW_PACKAGE_PREFIX}-python-lazy-loader>=0.4")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-pythran"
  "${MINGW_PACKAGE_PREFIX}-cython"
  "${MINGW_PACKAGE_PREFIX}-meson-python"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
  "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest>=8.3"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-cov>=2.11.0"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-localserver"
  "${MINGW_PACKAGE_PREFIX}-python-pooch")
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-pyamg: fast cg_mg mode of random walker segmentation")
options=('!strip' '!emptydirs')
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz")
sha256sums=('f5f970ab04efad85c24714321fcc91613fcb64ef2a892a13167df2f3e59199fa')

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}"
  cp -r "${_pyname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  msg "Python test for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m pytest
}

package() {
  msg "Python install for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  shopt -s globstar
  rm "${pkgdir}${MINGW_PREFIX}"/**/*.dll.a

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -Dm644 README.md "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/README.md"
}
