# 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}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=5.7.2
pkgrel=2
pkgdesc='A base package on which Jupyter projects rely (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: python-jupyter-core'
  'pypi: jupyter-core'
)
url='https://jupyter-core.readthedocs.io/'
msys2_repository_url='https://github.com/jupyter/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=('aa5f8d32bbf6b431ac830496da7392035d6f61b4f54872f15c4bd2a9c3f536d9')

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"
}
