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

_realname=nbconvert
pkgbase=mingw-w64-python-jupyter-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-jupyter-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-jupyter-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-jupyter-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-jupyter-${_realname}")
pkgver=7.16.4
pkgrel=3
pkgdesc="Convert Jupyter notebooks to other formats (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: jupyter-nbconvert'
  'pypi: nbconvert'
)
url='https://nbconvert.readthedocs.io/'
msys2_repository_url='https://github.com/jupyter/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=('86ca91ba266b0a448dc96fa6c5b9d98affabde2867b363258703536807f9f7f4')

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