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

_realname=nbformat
pkgbase=mingw-w64-python-${_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=5.4.0
pkgrel=1
pkgdesc="The base implementation of the Jupyter Notebook format and Python APIs for working with notebooks (mingw-w64)"
url="https://jupyter.org"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('BSD')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-fastjsonschema
    ${MINGW_PACKAGE_PREFIX}-python-jsonschema
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbconvert
    ${MINGW_PACKAGE_PREFIX}-python-jupyter_core
)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-setuptools)
source=("${_realname}-${pkgver}.tar.gz::https://github.com/jupyter/nbformat/archive/${pkgver}.tar.gz")
sha256sums=('18d566dfbe3da5ab15e9b1a8ad37b161c1755b5dc3e330fd4ae2b1b049cfdf65')

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

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root=${pkgdir} --optimize=1 --skip-build

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

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