# 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.3
pkgrel=1
pkgdesc="A Python Object-Document-Mapper for working with MongoDB"
arch=('any')
url="https://github.com/MongoEngine/mongoengine"
license=('MIT')
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=('6bd7b4f5553f6dc38752e57318efc4e634c13b44ef903a8661ab79a2d51d1d70c8a816c80764ee30acd1d2169f39865b833a8a41f294df34fe2f05ba6c280c18')

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
}
