# Maintainer: fsagbuya <fa@m-labs.ph>

_realname=pglive
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.8.2
pkgrel=1
pkgdesc="Live plot for PyqtGraph (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/domarm-comat/pglive"
msys2_references=(
    'pypi: pglive'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-pyqtgraph"
         "${MINGW_PACKAGE_PREFIX}-python-numpy")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-poetry-core")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pyqt5: for PyQt5 support"
            "${MINGW_PACKAGE_PREFIX}-python-pyqt6: for PyQt6 support"
            "${MINGW_PACKAGE_PREFIX}-python-pyside6: for PySide6 support")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-update-numpy-dep.patch")
sha256sums=('cbff6783d776705c5901905c59c1941369c1a91a79192b1aa02ed4a0b1137ec0'
            '77618d395382328aba9111812d5a6adde5bc43021c270f7c5e2d72a3d5281f6c')

prepare() {
  cd "${_realname}-${pkgver}"

  # Update numpy dependency to support 2.x
  patch -Np1 -i "${srcdir}/0001-update-numpy-dep.patch"
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "python-build-${MSYSTEM}"

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

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