# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=geoalchemy2
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.18.0
pkgrel=1
pkgdesc='Geospatial extension to SQLAlchemy (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://geoalchemy-2.readthedocs.io/'
msys2_repository_url='https://github.com/geoalchemy/geoalchemy2'
msys2_references=(
  'purl: pkg:pypi/geoalchemy2'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-python-shapely"
         "${MINGW_PACKAGE_PREFIX}-python-sqlalchemy")
optdepends=("${MINGW_PACKAGE_PREFIX}-libspatialite: support for SpatiaLite databases")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        '0001-geoalchemy2-0.17.1-search-spatialite.patch');
sha256sums=('9a04690cc33fbc580d15c7c028d9b1b1ea08271489730096c7092e1d486c2b7a'
            '13d320aef21f0ea56d6b6d70fc11c22c75e3fbb28e0ecc95da8805dae5ff4bec')

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

  patch -p1 -i "${srcdir}"/0001-geoalchemy2-0.17.1-search-spatialite.patch

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  python -m build --wheel --skip-dependency-check --no-isolation
}

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

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

  install -Dm644 COPYING.rst "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING.rst"
}
