# Contributor: Marcelo Duarte https://github.com/marcelotduarte

_realname=scikit-build-core
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.11.6
pkgrel=1
pkgdesc="A next generation Python CMake adaptor and Python API for plugins (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://scikit-build-core.readthedocs.io/'
msys2_repository_url='https://github.com/scikit-build/scikit-build-core'
msys2_references=(
  'purl: pkg:pypi/scikit-build-core'
)
license=('spdx:Apache-2.0')
depends=(
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-packaging"
  "${MINGW_PACKAGE_PREFIX}-python-pathspec"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-hatchling"
  "${MINGW_PACKAGE_PREFIX}-python-hatch-vcs"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
)
checkdepends=(
  "${MINGW_PACKAGE_PREFIX}-pybind11"
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-cattrs"
  "${MINGW_PACKAGE_PREFIX}-python-pip"
  "${MINGW_PACKAGE_PREFIX}-python-pytest"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-subprocess"
  "${MINGW_PACKAGE_PREFIX}-python-rich"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-virtualenv"
)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname//-/_}-${pkgver}.tar.gz")
sha256sums=('5982ccd839735be99cfd3b92a8847c6c196692f476c215da84b79d2ad12f9f1b')

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

check() {
  cd "build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/pip install ${_realname} -f dist --no-deps --no-index
  ${MINGW_PREFIX}/bin/python -m pytest -ra --showlocals -m "not broken_on_urct" -k "not sdist_time_hash_set_epoch and not sdist_hash and not symlink"
  ${MINGW_PREFIX}/bin/pip uninstall -y ${_realname}
}

package() {
  cd "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"
}

