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

EAPI=8

DISTUTILS_USE_PEP517=pdm-backend
PYTHON_COMPAT=( python3_{12..14} )

inherit distutils-r1

MY_PV="${PV/_p/.post}"
DESCRIPTION="Parse partial JSON generated by LLM"
HOMEPAGE="
	https://promplate.dev/partial-json-parser
	https://github.com/promplate/partial-json-parser
	https://pypi.org/project/partial-json-parser/
"
SRC_URI="
	https://github.com/promplate/${PN}/archive/refs/tags/v${MY_PV}.tar.gz
		-> ${P}.gh.tar.gz
"
S="${WORKDIR}/${PN}-${MY_PV}"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64 ~arm64"

PATCHES=( "${FILESDIR}/${P}-fix-empty-error-match.patch" )

# No required runtime deps; the only optional extra is `playground` which
# pulls dev-python/rich and ships the json-playground console script.
# Enable that extra by default — the binary is otherwise broken.
RDEPEND="
	dev-python/rich[${PYTHON_USEDEP}]
"
BDEPEND="
	test? (
		dev-python/tqdm[${PYTHON_USEDEP}]
	)
"

EPYTEST_PLUGINS=( hypothesis )
distutils_enable_tests pytest

python_test() {
	# test_performance.py runs benchmarks rather than correctness tests.
	epytest tests/test_examples.py tests/test_hypotheses.py
}