# Maintainer: Andrew Sun <adsun701@gmail.com>

_pyname=PyStemmer
_realname=pystemmer
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.2.0.3
pkgrel=2
pkgdesc="Snowball stemming algorithms, for information retrieval (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/pystemmer'
)
url="https://github.com/snowballstem/pystemmer/"
license=('spdx:MIT AND BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-libstemmer")
options=(!strip)
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('9ac74c8d0f3358dbb050f64cddbb8d55021d831d92305d7c20780ea8d6c0020e')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  rm -rf "${srcdir}"/python-build-${MSYSTEM} | true
  cp -r "${srcdir}"/"${_realname}-${pkgver}" "${srcdir}"/"python-build-${MSYSTEM}"
}

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

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