# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Carl Smedstad <carsme@archlinux.org>
# Contributor: Simon Sapin <simon dot sapin at exyr dot org>
# Contributor: Kyle Keen <keenerd@gmail.com>

pkgname=python-mongoengine
pkgver=0.29.1
pkgrel=4
pkgdesc="A Python Object-Document-Mapper for working with MongoDB"
url="https://github.com/MongoEngine/mongoengine"
license=('MIT')
arch=('any')
depends=(
  'python'
  'python-pymongo'
)
makedepends=(
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
)
checkdepends=(
  'python-mongomock'
  'python-pillow'
  'python-pytest'
)
optdepends=(
  'python-dateutil: for DateTimeField'
  'python-pillow: for ImageField / ImageGridFsProxy'
)
source=("$url/archive/v$pkgver/$pkgname-$pkgver.tar.gz")
b2sums=('6781abd5aa6c9dfbe6e56427878aae5a5f4e66189c2d4d82b80fcb8bd3b0afc8fbd8d7fcc0d0ee95888545e0e4411965ce8a13719231198e8f52c0327679f524')

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

check() {
  cd ${pkgname#python-}-$pkgver
  local pytest_args=(
    # Sub-selection of tests that don't require a running MongoDB instance.
    tests/all_warnings/test_warnings.py
    tests/queryset/test_field_list.py::TestQueryFieldList::test_always_include
    tests/queryset/test_field_list.py::TestQueryFieldList::test_empty
    tests/queryset/test_field_list.py::TestQueryFieldList::test_exclude_exclude
    tests/queryset/test_field_list.py::TestQueryFieldList::test_exclude_include
    tests/queryset/test_field_list.py::TestQueryFieldList::test_include_exclude
    tests/queryset/test_field_list.py::TestQueryFieldList::test_include_include
    tests/queryset/test_field_list.py::TestQueryFieldList::test_reset
    tests/queryset/test_field_list.py::TestQueryFieldList::test_using_a_slice
    tests/test_changelog_consistency.py
    tests/test_ci.py
    tests/test_common.py

    # Fails for Python 3.14
    # tests/test_connection.py::ConnectionTest::test___get_connection_settings
    tests/test_connection.py::ConnectionTest::test_connect

    tests/test_connection.py::ConnectionTest::test_connect_2_databases_uses_different_client_if_different_parameters
    tests/test_connection.py::ConnectionTest::test_connect_2_databases_uses_same_client_if_only_dbname_differs
    tests/test_connection_mongomock.py
    tests/test_datastructures.py
    tests/test_replicaset_connection.py
    tests/test_utils.py
  )
  pytest "${pytest_args[@]}"
}

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