# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=ipywidgets
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=8.1.8
pkgrel=1
pkgdesc="IPython widgets for the Jupyter Notebook (mingw-w64)"
url="https://github.com/jupyter-widgets/ipywidgets"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/ipywidgets'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python-ipython"
         "${MINGW_PACKAGE_PREFIX}-python-comm"
         "${MINGW_PACKAGE_PREFIX}-python-jsonschema")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-jupyterlab-widgets: widgets for Jupyter lab")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        '0001-ipywidgets-8.1.1-skip-opt-deps.patch')
sha256sums=('61f969306b95f85fba6b6986b7fe45d73124d1d9e3023a8068710d47a22ea668'
            'd15f4b7c52b27c349a7464cad2c8d90f2ecd689518ea0259c806ccab8d7ea33c')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

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

  apply_patch_with_msg \
    0001-ipywidgets-8.1.1-skip-opt-deps.patch
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
