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

_realname=nbconvert
pkgbase=mingw-w64-python-jupyter-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-jupyter-${_realname}")
pkgver=7.16.6
pkgrel=1
pkgdesc="Convert Jupyter notebooks to other formats (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://nbconvert.readthedocs.io/'
msys2_repository_url='https://github.com/jupyter/nbconvert/'
msys2_references=(
  'archlinux: jupyter-nbconvert'
  'purl: pkg:pypi/nbconvert'
)
license=('spdx:BSD-3-Clause')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-bleach
    ${MINGW_PACKAGE_PREFIX}-python-beautifulsoup4
    ${MINGW_PACKAGE_PREFIX}-python-defusedxml
    ${MINGW_PACKAGE_PREFIX}-python-jinja
    ${MINGW_PACKAGE_PREFIX}-python-jupyter_core
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbclient
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbformat
    ${MINGW_PACKAGE_PREFIX}-python-jupyterlab-pygments
    ${MINGW_PACKAGE_PREFIX}-python-lxml
    ${MINGW_PACKAGE_PREFIX}-python-markupsafe
    ${MINGW_PACKAGE_PREFIX}-python-mistune
    ${MINGW_PACKAGE_PREFIX}-python-packaging
    ${MINGW_PACKAGE_PREFIX}-python-pandocfilters
    ${MINGW_PACKAGE_PREFIX}-python-pygments
    ${MINGW_PACKAGE_PREFIX}-python-tinycss2
    ${MINGW_PACKAGE_PREFIX}-python-traitlets)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-build
    ${MINGW_PACKAGE_PREFIX}-python-installer
    ${MINGW_PACKAGE_PREFIX}-python-hatchling)
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('576a7e37c6480da7b8465eefa66c17844243816ce1ccc372633c6b71c3c0f582')

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() {
  msg "Python test for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  #Todo: Fix a test and possibly nbconvert. The problem is that it attempts
  #to use inkscape but it locates it using the Windows registry and the MINGW
  #version from these doesn't set the registry.
  ${MINGW_PREFIX}/bin/py.test --pyargs nbconvert || true
}

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"
}
