# Maintainer: Patrick Stewart <patstew@gmail.com>

_realname=ipykernel
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=6.29.5
pkgrel=2
pkgdesc="The ipython kernel for Jupyter (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://ipython.org/"
msys2_repository_url="https://github.com/ipython/ipykernel"
msys2_references=(
  'pypi: ipykernel'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python-debugpy"
         "${MINGW_PACKAGE_PREFIX}-python-ipython"
         "${MINGW_PACKAGE_PREFIX}-python-comm"
         "${MINGW_PACKAGE_PREFIX}-python-traitlets"
         "${MINGW_PACKAGE_PREFIX}-python-jupyter_client"
         "${MINGW_PACKAGE_PREFIX}-python-jupyter_core"
         "${MINGW_PACKAGE_PREFIX}-python-nest-asyncio"
         "${MINGW_PACKAGE_PREFIX}-python-tornado"
         "${MINGW_PACKAGE_PREFIX}-python-matplotlib-inline"
         "${MINGW_PACKAGE_PREFIX}-python-pyzmq"
         "${MINGW_PACKAGE_PREFIX}-python-psutil"
         "${MINGW_PACKAGE_PREFIX}-python-packaging")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-hatchling")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('f093a22c4a40f8828f8e330a9c297cb93dcab13bd9678ded6de8e5cf81c56215')

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

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

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
}

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

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

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