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

_realname=ruamel.yaml.clib
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.2.15
pkgrel=1
pkgdesc='C version of reader, parser and emitter for ruamel.yaml derived from libyaml (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'anitya: 131030'
  'archlinux: python-ruamel.yaml.clib'
  'purl: pkg:pypi/ruamel-yaml-clib'
)
url="https://sourceforge.net/projects/ruamel-yaml-clib/"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-cc"
)
source=("https://files.pythonhosted.org/packages/source/${_realname:0:1}/${_realname}/${_realname//./_}-${pkgver}.tar.gz")
sha256sums=('46e4cc8c43ef6a94885f72512094e482114a8a706d3c555a34ed4b0d20200600')

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

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  # Workaround for GCC 14, see https://sourceforge.net/p/ruamel-yaml-clib/tickets/22/
  CFLAGS+=" -Wno-error=incompatible-pointer-types"

  # clang build workaround
  # TODO: maybe cython regen would help too? but cython sources are not included in the tarball
  CFLAGS+=" -Wno-incompatible-function-pointer-types"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

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