# Maintainer: Patrick Stewart <patstew@gmail.com>
# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=jupyter_core
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=5.9.1
pkgrel=1
pkgdesc='A base package on which Jupyter projects rely (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://jupyter-core.readthedocs.io/'
msys2_repository_url='https://github.com/jupyter/jupyter_core/'
msys2_references=(
  'archlinux: python-jupyter-core'
  'purl: pkg:pypi/jupyter-core'
)
license=('spdx:BSD-3-Clause')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-platformdirs
    ${MINGW_PACKAGE_PREFIX}-python-pywin32
    ${MINGW_PACKAGE_PREFIX}-python-traitlets)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-build
    ${MINGW_PACKAGE_PREFIX}-python-hatchling
    ${MINGW_PACKAGE_PREFIX}-python-installer)
checkdepends=(
    ${MINGW_PACKAGE_PREFIX}-python-pytest
    ${MINGW_PACKAGE_PREFIX}-python-nose)
options=('!strip')
source=(https://pypi.org/packages/source/${_realname::1}/${_realname/_/-}/${_realname}-${pkgver}.tar.gz)
sha256sums=('4d09aaff303b9566c3ce657f580bd089ff5c91f5f89cf7d8846c3cdf465b5508')

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

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  pytest -v \
    --deselect jupyter_core/tests/test_command.py::test_not_on_path \
    --deselect jupyter_core/tests/test_command.py::test_path_priority \
    --deselect jupyter_core/tests/test_command.py::test_argv0 \
    --deselect jupyter_core/tests/test_paths.py::test_jupyter_path_prefer_env # https://github.com/jupyter/jupyter_core/issues/208
}

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

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

  find "${pkgdir}/" -type d -empty -delete

  install -Dm644 "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
