# 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.1.3
pkgrel=1
pkgdesc="The base implementation of the Jupyter Notebook format and Python APIs for working with notebooks (mingw-w64)"
url="https://pypi.python.org/pypi/nbformat"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-traitlets"
         "${MINGW_PACKAGE_PREFIX}-python-jsonschema"
         "${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=('437b72e20eaa76230cdfe48cf388551a1ebc5880e9251aa7f614dbc4680c9ea3')

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

build() {

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

}

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

  install -D -m644 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
}
