# Maintainer: Dirk Stolle

_realname=passagemath-repl
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=10.6.42
pkgrel=1
pkgdesc="passagemath: IPython kernel, Sage preparser, doctester (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/passagemath/passagemath'
msys2_references=(
  'purl: pkg:pypi/passagemath-repl'
)
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-python-ipython"
         "${MINGW_PACKAGE_PREFIX}-python-ipykernel"
         "${MINGW_PACKAGE_PREFIX}-python-ipywidgets"
         "${MINGW_PACKAGE_PREFIX}-python-jupyter_client"
         "${MINGW_PACKAGE_PREFIX}-python-passagemath-environment"
         "${MINGW_PACKAGE_PREFIX}-python-passagemath-objects"
         "${MINGW_PACKAGE_PREFIX}-python-typing_extensions")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-passagemath-setup"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname/-/_}-${pkgver}.tar.gz")
sha256sums=('83661ce3c422c2dd4d253a0cad752832bd51c8e639aae88ea507554ceb25bd8d')

build() {
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  # fix wrong shebang created by python-installer
  sed -i 's|#!<launcher_dir>\\python.exe|#!/usr/bin/env sage-python|g' \
    "${pkgdir}${MINGW_PREFIX}/bin/sage-cleaner" \
    "${pkgdir}${MINGW_PREFIX}/bin/sage-eval" \
    "${pkgdir}${MINGW_PREFIX}/bin/sage-fixdoctests" \
    "${pkgdir}${MINGW_PREFIX}/bin/sage-ipython" \
    "${pkgdir}${MINGW_PREFIX}/bin/sage-notebook" \
    "${pkgdir}${MINGW_PREFIX}/bin/sage-preparse" \
    "${pkgdir}${MINGW_PREFIX}/bin/sage-run" \
    "${pkgdir}${MINGW_PREFIX}/bin/sage-run-cython" \
    "${pkgdir}${MINGW_PREFIX}/bin/sage-runtests" \
    "${pkgdir}${MINGW_PREFIX}/bin/sage-startuptime.py"

  sed -i 's|#!<launcher_dir>\\python.exe|#!/usr/bin/env python3|g' \
    "${pkgdir}${MINGW_PREFIX}/bin/sage-coverage"
}
