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

EAPI=8

DISTUTILS_USE_PEP517="setuptools"
PYTHON_COMPAT=( python3_{12..13} )

inherit distutils-r1

DESCRIPTION="CLI interface to GNU Emacs"
HOMEPAGE="https://codeberg.org/xgqt/xgqt-python-app-etask/"

if [[ "${PV}" == *9999* ]] ; then
	inherit git-r3

	EGIT_REPO_URI="https://codeberg.org/xgqt/xgqt-python-app-${PN}"
else
	SRC_URI="https://codeberg.org/xgqt/xgqt-python-app-${PN}/archive/${PV}.tar.gz
		-> ${P}.codeberg.tar.gz"
	S="${WORKDIR}/xgqt-python-app-${PN}"

	KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ppc ~ppc64 ~sparc ~x86"
fi

LICENSE="GPL-3"
SLOT="0"
IUSE="doc"

COMMON_DEPEND="
	dev-python/colorama[${PYTHON_USEDEP}]
"
RDEPEND="
	${COMMON_DEPEND}
	>=app-editors/emacs-23.1:*
"
BDEPEND="
	${COMMON_DEPEND}
	doc? (
		app-text/doxygen
	)
"

DOCS=( "${S}"/README.md "${S}"/logo.png )

PATCHES=(
	"${FILESDIR}"/${PN}-python-requires.patch
)

EPYTEST_DESELECT=(
	# float("32.0.50") raises ValueError, the test only handles
	# two-component versions
	"tests/integration/test_emacs.py::test_emacs_version"
)

distutils_enable_tests pytest

src_compile() {
	( cd "./src/${PN}" \
		  && distutils-r1_src_compile )

	if use doc ; then
		emake docs
	fi
}

src_install() {
	( cd "./src/${PN}" \
		  && distutils-r1_src_install )

	if use doc ; then
		dodoc -r ./docs/artifacts/{html,latex}
		doman ./docs/artifacts/man/man3/*
	fi

	einstalldocs
}