# Maintainer: Patrick Stewart <patstew@gmail.com>

_realname=ipykernel
pkgbase=mingw-w64-python3-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=5.1.0
pkgrel=1
pkgdesc="The ipython kernel for Jupyter (mingw-w64)"
arch=('any')
url="https://ipython.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python3-ipython"
         "${MINGW_PACKAGE_PREFIX}-python3-pathlib2"
         "${MINGW_PACKAGE_PREFIX}-python3-pyzmq"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter_client"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter_core")
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python3-pytest"
              "${MINGW_PACKAGE_PREFIX}-python3-mock"
              "${MINGW_PACKAGE_PREFIX}-python3-nose")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/ipython/${_realname}/archive/${pkgver}.tar.gz")
sha256sums=('30f01a2a1470d3fabbad03f5c43606c1bc2142850fc4ccedcf44281664ae9122')

prepare() {
  cd "${srcdir}"
  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}"
  ${MINGW_PREFIX}/bin/python3 -m pytest || warning "Tests failed"
}

package() {
  #install=ipython3-${CARCH}.install
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-pathlib2"
           "${MINGW_PACKAGE_PREFIX}-python3-pyzmq"
           "${MINGW_PACKAGE_PREFIX}-python3-ipython")

  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

  find "${pkgdir}/" -name "*.pyc" -delete
  find "${pkgdir}/" -type d -empty -delete

  # setuptools doesnt see mingw-w64-python's readline
  find "${pkgdir}/" -name 'requires.txt' -delete

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

