# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=python-elasticsearch
pkgver=7.9.0
pkgrel=6
arch=('any')
pkgdesc='Python client for Elasticsearch'
url='https://github.com/elastic/elasticsearch-py'
license=('Apache-2.0')
depends=('python-certifi' 'python-urllib3')
makedepends=('python-build' 'python-installer' 'python-setuptools' 'python-wheel')
checkdepends=('python-requests' 'python-yaml' 'python-pytest' 'python-numpy'
              'python-pandas' 'python-aiohttp' 'python-pytest-asyncio')
source=("$pkgname-$pkgver.tar.gz::$url/archive/$pkgver.tar.gz"
        python310.patch
        $pkgname-7.9.0-remove_mock.patch
	assert-regex-deprecated.patch)
sha512sums=('2fae863434f7bf06c0669426b4a261f5d0c9ea26bd68783393bf25521e46484a0d6267438ae73590b7961b2a1b1a347cf89f33a9904983a82469b25b14894657'
            '495694c1d89ad453fd1d2e83092a741a256cbe5627ebcca22770b340a9ac77fabcdea83fa84f1c9c0ffe734517a099f98ee8a95f1384b5f716eb34273a21b39f'
            '7987b3080eb80b617b3a5b63a5939a8c8d2016686aae246c06c2c009490cab6aa30ff2cf9ab77c68abdc6e998284034abc50fff18da74cf647c95725a6862adf'
            'd72faf95c63e65ccc7e120ce2a8bddaeeb68f655c8e6bf9011227dabddb76cd63b7c4ae5da31c6936b20ad4d63945bc61d0c64120796d0a1d84aec66313ead12')

prepare() {
  cd elasticsearch-py-$pkgver
  patch -Np1 -F3 -i ../python310.patch
  patch -Np1 -i ../$pkgname-7.9.0-remove_mock.patch
  patch -Np1 -i ../assert-regex-deprecated.patch
}

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

check() {
  cd elasticsearch-py-$pkgver
  # Skip tests that requires a running elasticsearch server
  #TEST_ES_REPO="$srcdir"/elasticsearch
  # TODO: test_elasticsearch/test_async/test_transport.py::TestTransport::test_sniff_on_fail_failing_does_not_prevent_retires
  pytest --deselect test_elasticsearch/test_async/test_server --deselect  test_elasticsearch/test_async/test_transport.py::TestTransport::test_sniff_on_fail_failing_does_not_prevent_retires
}

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