# Maintainer: Bruno Pagani <archange@archlinux.org>

_pkg=Fiona
pkgname=python-${_pkg,,}
pkgver=1.10.1
pkgrel=3
pkgdesc="Read and write geographic data files"
arch=(x86_64 aarch64)
url="https://github.com/Toblerity/Fiona"
license=(BSD-3-Clause)
depends=(
    gdal
    python-attrs
    python-certifi
    python-click
    python-click-plugins
    python-cligj
    python-munch
)
optdepends=(
    'python-shapely: fio-calc functionnality'
    'python-boto3: s3 support'
)
makedepends=(
    cython
    python-build
    python-installer
    python-setuptools
    python-wheel
)
checkdepends=(python-pytest python-boto3 python-pytz python-shapely)
#source=(https://files.pythonhosted.org/packages/source/${_pkg::1}/${_pkg}/${_pkg}-${pkgver}.tar.gz)
source=(https://github.com/Toblerity/Fiona/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha256sums=('308e12c33d34141c2ff2ba94ebcc7c9226f5d17882a5b51ef064f0283d67dc88')

prepare() {
  sed -i '/oldest-supported-numpy/d' ${_pkg}-${pkgver}/pyproject.toml
  sed -i 's|\~=|>=|' ${_pkg}-${pkgver}/pyproject.toml # Fix build with cython 3.1
}

build() {
  cd ${_pkg}-${pkgver}
  CFLAGS+=" -Wno-incompatible-pointer-types" \
  python -m build --wheel --no-isolation
}

check() {
  cd ${_pkg}-${pkgver}
  mv fiona{,.bak} # Avoid non-working local import
  local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
  # Currently they are 66 failing tests but no time to investigate
  PYTHONPATH="${PWD}"/build/lib.linux-${CARCH}-${python_version}/ pytest -vv --color=yes -m "not wheel" || echo "Warning: failed tests"
  mv fiona{.bak,}
}

package() {
  cd ${_pkg}-${pkgver}
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm644 LICENSE.txt -t "${pkgdir}"/usr/share/licenses/${pkgname}
}
