# Maintainer: ciciwu <yw@m-labs.hk>

_realname=pyqtgraph
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.13.3
pkgrel=2
pkgdesc='Scientific Graphics and GUI Library for Python.'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://www.pyqtgraph.org/"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-numpy")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pyqt5"
            "${MINGW_PACKAGE_PREFIX}-python-pyside2-qt5"
            $([[ "${CARCH}" == "i686" ]] || echo "${MINGW_PACKAGE_PREFIX}-python-pyqt6")
            $([[ "${CARCH}" == "i686" ]] || echo "${MINGW_PACKAGE_PREFIX}-python-pyside6")
            "${MINGW_PACKAGE_PREFIX}-python-scipy: Image processing & Data array filtering"
            "${MINGW_PACKAGE_PREFIX}-python-pyopengl: 3D graphics & Faster image processing"
            "${MINGW_PACKAGE_PREFIX}-python-h5py: Export in hdf5 format"
            "${MINGW_PACKAGE_PREFIX}-python-matplotlib: Export of PlotItem in matplotlib figure & Add matplotlib collection of colormaps"
            "${MINGW_PACKAGE_PREFIX}-python-numba: Faster image processing")
source=("https://github.com/pyqtgraph/pyqtgraph/archive/refs/tags/pyqtgraph-${pkgver}.tar.gz")
sha256sums=('2dd03b68543fba85aea04e3c07311bfe7d5fd87f40ad6954e83b261d23f92de1')

prepare() {
  cd "${srcdir}"

  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

# Note that build() is sometimes skipped because it's done in 
# the packages setup.py install for simplicity if you can do so.
# but sometimes, you want to do a check before install which would
# also trigger the build.
build() {
  msg "Python build for ${MSYSTEM}"  
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

#check() {
#  msg "Python test for ${MSYSTEM}"
#  cd "${srcdir}/python-build-${MSYSTEM}"
#  PYTHONPATH=. ${MINGW_PREFIX}/bin/pytest .
#}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  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

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

}
