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

_realname=ipykernel
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=5.5.5
pkgrel=1
pkgdesc="The ipython kernel for Jupyter (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://ipython.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python-ipython"
         "${MINGW_PACKAGE_PREFIX}-python-ipython_genutils"
         "${MINGW_PACKAGE_PREFIX}-python-pathlib2"
         "${MINGW_PACKAGE_PREFIX}-python-pyzmq"
         "${MINGW_PACKAGE_PREFIX}-python-tornado"
         "${MINGW_PACKAGE_PREFIX}-python-traitlets"
         "${MINGW_PACKAGE_PREFIX}-python-jupyter_client")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-mock"
              "${MINGW_PACKAGE_PREFIX}-python-nose")
#install=ipython3-${CARCH}.install
source=("${_realname}-${pkgver}.tar.gz::https://github.com/ipython/${_realname}/archive/${pkgver}.tar.gz")
sha256sums=('82585b4067b38f3b3bf09a233b7bc9e6c6f51446693ad14d302f06ff35189990')

prepare() {
  cd "${srcdir}"
  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
}

check() {
  msg "Python test for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  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

  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/python-${_realname}/LICENSE"
}

