# Contributor: Liu Pak Hin <wl@m-labs.hk>

_realname=rapidfuzz
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.14.1
pkgrel=1
pkgdesc="Rapid fuzzy string matching. (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'anitya: 86678'
  'archlinux: python-rapidfuzz'
  'gentoo: dev-python/rapidfuzz'
  'purl: pkg:pypi/rapidfuzz'
)
license=('spdx:MIT')
url="https://rapidfuzz.github.io/RapidFuzz/"
msys2_repository_url="https://github.com/rapidfuzz/RapidFuzz/"
msys2_changelog_url='https://github.com/rapidfuzz/RapidFuzz/blob/main/CHANGELOG.rst'
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-scikit-build-core"
             "${MINGW_PACKAGE_PREFIX}-rapidfuzz-cpp"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-cov"
              "${MINGW_PACKAGE_PREFIX}-python-hypothesis"
              "${MINGW_PACKAGE_PREFIX}-python-pytest")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-build-clang.patch")
sha256sums=('b02850e7f7152bd1edff27e9d584505b84968cacedee7a734ec4050c655a803c'
            'd40345312c73b0f5d1c2f95ba678210228820892e3d162f9d90240c08557cb9b')

prepare(){
  cd "RapidFuzz-${pkgver}"
  patch -p1 -i "${srcdir}/0001-fix-build-clang.patch"
  cd -

  cp -r "RapidFuzz-${pkgver}" "python-build-${MSYSTEM}"
  rm -rf "python-build-${MSYSTEM}/extern"
  cp -r "${_realname}-${pkgver}/extern" "python-build-${MSYSTEM}/extern"
}

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

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m pytest || 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/${_realname}/LICENSE"
}
