# Maintainer: No one

_pyname=Rtree
_realname=rtree
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.2.0
pkgrel=3
pkgdesc="Rtree: spatial index for Python GIS (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/Toblerity/rtree'
msys2_references=(
  'pypi: Rtree'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-spatialindex")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-wheel")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz"
        "0001-fix-mingw-finder.patch"
        "0002-drop-spatialindex-version-test.patch::https://github.com/Toblerity/rtree/commit/9a08ab91.patch")
sha256sums=('f5145f7852bf7f95c126fb16bf1a4c2ca9300ae151b07f8a0f7083ea47912675'
            '880d0077ae4dd3d3bd06b0a1ca67eb0539f5be3e23e63ecc6662ed03560cf4e6'
            '12ac1f37021d57e9eeeed6819e3ac6360a321bba2bb52e9936acfdcd7e5e965c')

prepare() {
  cd "${_pyname}-${pkgver}"

  patch -Np1 -i "${srcdir}"/0001-fix-mingw-finder.patch
  patch -Np1 -i "${srcdir}"/0002-drop-spatialindex-version-test.patch

  cd "${srcdir}"
  rm -rf "python-build-${MSYSTEM}"
  cp -r "${_pyname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "python-build-${MSYSTEM}"

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

check() {
  cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m pytest
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
