# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DISTUTILS_USE_PEP517=hatchling
PYTHON_COMPAT=( python3_{10..13} )

inherit distutils-r1 pypi

DESCRIPTION="Python bindings for libmongocrypt"
HOMEPAGE="
	https://github.com/mongodb/libmongocrypt/
	https://pypi.org/project/pymongocrypt
"

LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~loong ~ppc ~ppc64 ~riscv ~sparc ~x86"

RDEPEND="
	>=dev-libs/libmongocrypt-1.11.0
	dev-python/cffi[${PYTHON_USEDEP}]
	dev-python/cryptography[${PYTHON_USEDEP}]
	dev-python/packaging[${PYTHON_USEDEP}]
	dev-python/httpx[${PYTHON_USEDEP}]

"
BDEPEND="
	test? (
		dev-python/pymongo[${PYTHON_USEDEP}]
		dev-python/pymongo-auth-aws[${PYTHON_USEDEP}]
		dev-python/respx[${PYTHON_USEDEP}]
		dev-python/unasync[${PYTHON_USEDEP}]
	)
"

distutils_enable_tests pytest

src_prepare() {
	distutils-r1_src_prepare
	# we do not want hatch-requirements-txt and its ton of NIH deps
	sed -i -e '/requirements/d' pyproject.toml || die
}

python_test() {
	local EPYTEST_DESELECT=(
		# slow
		test/performance/perf_test.py::TestBulkDecryption::runTest
		# needs mongodb-enterprise-6+ (crypt_shared)
		test/test_mongocrypt.py::TestMongoCrypt::test_encrypt
		test/test_mongocrypt.py::TestMongoCryptCallback::test_crypt_shared
		test/test_mongocrypt.py::TestMongoCryptCallback::test_encrypt
		test/test_mongocrypt.py::TestExplicitEncryption::test_range_query_int32
		test/test_mongocrypt.py::TestAsyncMongoCryptCallback::test_crypt_shared
		test/test_mongocrypt.py::TestAsyncMongoCryptCallback::test_encrypt
		test/test_mongocrypt.py::TestAsyncExplicitEncryption::test_range_query_int32
	)
	epytest
}