# Maintainer: George Rawlinson
# Contributor: Pekka Ristola <pekkarr [at] protonmail [dot] com>
# Contributor: Caltlgin Stsodaat <contact@fossdaily.xyz>

pkgname=python-rapidfuzz
pkgver=3.14.3
pkgrel=1
pkgdesc='Rapid fuzzy string matching in Python using various string metrics'
arch=(x86_64 aarch64)
url='https://github.com/rapidfuzz/RapidFuzz'
license=(MIT)
depends=(
  glibc
  gcc-libs
  python
)
makedepends=(
  git
  python-build
  python-installer
  cython
  python-scikit-build-core
  rapidfuzz-cpp
)
checkdepends=(
  python-hypothesis
  python-pandas
  python-pytest
)
optdepends=(python-numpy)
source=(
  "$pkgname::git+$url#tag=v$pkgver"
  'github.com-taskflow-taskflow::git+https://github.com/taskflow/taskflow'
  remove-version-constraints.patch
)
sha512sums=('ebdcb6da29758c00062e52a896f6ddc13d56986ac83f26fb85fca76c11e52b0dd2d3a8b6efab378625d5d5fad9f0acdcb2f36c0e02e2d8c5fedd90a6a35848a1'
            'SKIP'
            '43771f873fbf91e3bad9a1e0653e30ec54523a278195ea642622f15ab2fdcbdf0d2037819ce01e0f0e6d445a36695bd8f4638ce1be80a2bdcbbc83ec516fa01a')
b2sums=('0a49b206ff0f1ebfde670db068bf0225137c217c45fc392e2ab4aff0b95545026dde377461852789995c486b5a4c72ddf570dbbcd207b40620297d33c6e294b2'
        'SKIP'
        '156581b1e900d951008e489c22e887728baf0f014ea6e4848226ceca683baa16b7f8bcd979b7db42e9e65b029fd74fe9f66c10862a53ed8e08bc6142af406370')

prepare() {
  cd "$pkgname"

  # prepare git submodules
  git submodule init extern/taskflow
  git config submodule.extern/taskflow.url "$srcdir/github.com-taskflow-taskflow"
  git -c protocol.file.allow=always submodule update

  patch -p1 -i "$srcdir/remove-version-constraints.patch"
}

build() {
  cd "$pkgname"

  RAPIDFUZZ_BUILD_EXTENSION=1 \
    python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  # install to temporary directory
  python -m installer --destdir="$PWD/tmp_install" dist/*.whl

  PYTHONPATH="$PWD/tmp_install$site_packages" pytest -v

}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
