# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=scikit-image
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.18.1
pkgrel=2
pkgdesc='Image processing routines for SciPy (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://scikit-image.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python-matplotlib>3.0.0"
"${MINGW_PACKAGE_PREFIX}-python-scipy>=1.0.1"
"${MINGW_PACKAGE_PREFIX}-python-pywavelets>=1.1.1"
"${MINGW_PACKAGE_PREFIX}-python-numpy>1.18.0"
"${MINGW_PACKAGE_PREFIX}-python-networkx>=2.0"
"${MINGW_PACKAGE_PREFIX}-python-imageio>=2.3.0"
"${MINGW_PACKAGE_PREFIX}-python-tifffile>=2019.7.26"
"${MINGW_PACKAGE_PREFIX}-python-pillow>7.1.1")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "${MINGW_PACKAGE_PREFIX}-cython")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest>=5.2.0"
"${MINGW_PACKAGE_PREFIX}-python-pytest-cov>=2.7.0"
"${MINGW_PACKAGE_PREFIX}-python-pytest-flake8"
"${MINGW_PACKAGE_PREFIX}-python-pytest-localserver"
"${MINGW_PACKAGE_PREFIX}-python-pooch")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pyqt5: for imshow(x, fancy=True) and skivi"
"${MINGW_PACKAGE_PREFIX}-freeimage: for reading various types of image file formats"
"${MINGW_PACKAGE_PREFIX}-python-pyamg: fast cg_mg mode of random walker segmentation")
options=('!emptydirs')
source=("https://files.pythonhosted.org/packages/source/${_realname:0:1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('fbb618ca911867bce45574c1639618cdfb5d94e207432b19bc19563d80d2f171')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build_ext --inplace
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done

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