# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=cloudpickle
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.1.1
pkgrel=1
pkgdesc='Extended pickling support for Python objects (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/cloudpickle'
)
url="https://github.com/cloudpipe/cloudpickle"
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
"${MINGW_PACKAGE_PREFIX}-python-psutil"
"${MINGW_PACKAGE_PREFIX}-python-tornado"
"${MINGW_PACKAGE_PREFIX}-python-numpy")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-flit-core")
options=('!emptydirs')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('b216fa8ae4019d5482a8ac3c95d8f6346115d8835911fd4aefd1a445e4242c64')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}/tests/cloudpickle_testpkg"
  ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
  cd ../..
  PYTHONPATH="$PWD/tests/cloudpickle_testpkg/build/lib/" \
  ${MINGW_PREFIX}/bin/pytest --deselect tests/cloudpickle_file_test.py::CloudPickleFileTests::test_pickling_special_file_handles \
    --deselect tests/cloudpickle_test.py::CloudPickleTest::test_pickling_file_handles \
    --deselect tests/cloudpickle_test.py::Protocol2CloudPickleTest::test_pickling_file_handles || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl
  #install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
