# Maintainer: Carl Smedstad <carsme@archlinux.org>
# Contributor: Felix Yan <felixonmars@archlinux.org>

pkgname=python-elasticsearch
_pkgname=elasticsearch-py
pkgver=9.2.0
pkgrel=1
arch=(any)
pkgdesc="Official Python client for Elasticsearch"
url="https://github.com/elastic/elasticsearch-py"
license=(Apache-2.0)
depends=(
  python
  python-dateutil
  python-elastic-transport
  python-typing_extensions
)
makedepends=(
  python-build
  python-hatchling
  python-installer
  python-wheel
)
checkdepends=(
  nltk-data
  python-aiohttp
  python-nltk
  python-numpy
  python-orjson
  python-pandas
  python-pyarrow
  python-pydantic
  python-pytest
  python-pytest-asyncio
  python-requests
  # Not available in Arch repos (yet)
  # python-simsimd
  python-trio
  python-yaml
)
optdepends=(
  'python-aiohttp: support for asynchronous requests'
  'python-numpy: support for Maximal Marginal Relevance (MMR) for search results'
  'python-orjson: support for faster JSON serialization'
  'python-pyarrow: support for Arrow deserialization'
  'python-requests: support for synchronous requests'
  # 'python-simsimd: support for Maximal Marginal Relevance (MMR) for search results'
)
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha256sums=('e2e6a5d609e1b07c739dab907c4d10eb0eae8ca4476333217232045cb9550f08')

build() {
  cd $_pkgname-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd $_pkgname-$pkgver
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  # Ignored tests requires unpackaged sentence_transformers
  test-env/bin/python -m pytest --override-ini="addopts=" \
    --ignore=test_elasticsearch/test_dsl/test_integration/test_examples/_async/test_vectors.py \
    --ignore=test_elasticsearch/test_dsl/test_integration/test_examples/_sync/test_vectors.py
}

package() {
  cd $_pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
}
