# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Kyle Keen <keenerd@gmail.com>
# Contributor: PepeSmith
# Contributor: Aron Asor <aronasorman at gmail.com>
# Contributor: Chris Brannon <chris@the-brannons.com>
# Contributor: Douglas Soares de Andrade <dsa@aur.archlinux.org>

pkgname=ipython
pkgver=9.7.0
pkgrel=1
pkgdesc='Enhanced Interactive Python shell'
arch=(any)
url=https://ipython.org
license=(BSD-3-Clause)
depends=(
  python-decorator
  python-ipython-pygments-lexers
  python-jedi
  python-matplotlib-inline
  python-pexpect
  python-prompt_toolkit
  python-pygments
  python-stack-data
  python-traitlets
  sqlite
)
makedepends=(
  git
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(
  jupyter-nbformat
  python-curio
  python-ipykernel
  python-matplotlib
  python-numpy
  python-pandas
  python-pytest
  python-pytest-asyncio
  python-testpath
  python-trio
  tcsh
  texlive-bin
  texlive-latex
)
optdepends=(
  'python-black: to auto format with Black'
  'python-pickleshare: for the ip.db database'
  'yapf: to auto format with YAPF'
)
source=(
  "git+https://github.com/ipython/ipython.git#tag=$pkgver"
  'IPython-icon.png::https://www.packal.org/sites/default/files/public/styles/icon_large/public/workflow-files/nkeimipynbworkflow/icon/icon.png'
)
b2sums=('93c5378f662c80870e85d619ddf1ead886a1981b57d50051a3071b14ac2f67422a525f85a334325e2a800640ad15884d0f1df73a1f12aea05aa25fc4603a912a'
        'd445e2bc7a037db8715ea103611720e965987e155c32e445b0ef783e519fca8a0301b16c5763fd9a5d8d169c3b0d7b4db6c0bd0f9772842258b135dcb1d6d5a2')
#validpgpkeys=(
#  99B17F64FD5C94692E9EF8064968B2CC0208DCC8 # Matthias Bussonnier <bussonniermatthias@gmail.com>
#  4D9D285A538F7C2E16D13ACE57982D11F0EA2247 # Michał Krassowski
#)

build() {
  cd $pkgname
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd $pkgname
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest -v
}

package() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/$pkgname-$pkgver.dist-info/licenses/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname

  # FS#47046
  install -Dm644 IPython-icon.png "$pkgdir"/usr/share/pixmaps/ipython.png

  cd $pkgname
  python -m installer --destdir="$pkgdir" dist/*.whl

  cd 'examples/IPython Kernel'
  # FS#45120
  sed -i 's/gnome-netstatus-idle/ipython/' ipython.desktop
  install -Dm644 -t "$pkgdir"/usr/share/applications ipython.desktop
}
