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

_realname=nbconvert
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python3-jupyter-${_realname}")
pkgver=5.4
pkgrel=2
pkgdesc="Convert Jupyter notebooks to other formats (mingw-w64)"
arch=('any')
url='https://pypi.python.org/pypi/nbconvert'
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python3"
         "${MINGW_PACKAGE_PREFIX}-python3-defusedxml"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter_client"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter-nbformat"
         "${MINGW_PACKAGE_PREFIX}-python3-pygments"
         "${MINGW_PACKAGE_PREFIX}-python3-mistune"
         "${MINGW_PACKAGE_PREFIX}-python3-jinja"
         "${MINGW_PACKAGE_PREFIX}-python3-entrypoints"
         "${MINGW_PACKAGE_PREFIX}-python3-traitlets"
         "${MINGW_PACKAGE_PREFIX}-python3-pandocfilters"
         "${MINGW_PACKAGE_PREFIX}-python3-bleach"
         "${MINGW_PACKAGE_PREFIX}-python3-testpath"
         )
install=${_realname}3-${CARCH}.install
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/jupyter/${_realname}/archive/${pkgver}.tar.gz")
sha256sums=('7fc506624b9715a607abc7cc189b9d70fe73a483974a42a389f8188d1a8e3d0c')

prepare() {
  rm -rf python3-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python3-build-${CARCH}"
}

build() {
  msg "Python 3 build for ${CARCH}"
  cd "${srcdir}/python3-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

check() {
  msg "Python 3 test for ${CARCH}"
  cd "${srcdir}/python3-build-${CARCH}"
#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}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in ${pkgdir}${MINGW_PREFIX}/bin/*.py; do
    sed -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i ${_f}
  done

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

