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

EAPI=8

PYTHON_COMPAT=( python3_{10..14} )
DISTUTILS_USE_PEP517=setuptools
# so that python_fix_shebang doesn't break
DISTUTILS_SINGLE_IMPL=1

# TODO: tests
# TODO: zsh completion

inherit pypi distutils-r1 optfeature bash-completion-r1

DESCRIPTION="Simple, standards-based, command line todo (aka: task) manager. "
HOMEPAGE="
	https://todoman.readthedocs.io/
	https://github.com/pimutils/todoman
"
#SRC_URI=""

LICENSE="ISC"
SLOT="0"
KEYWORDS="~amd64"

DEPEND="
	dev-python/click
	>=dev-python/click-log-0.2.1
	dev-python/humanize
	>=dev-python/icalendar-4.0.3
	dev-python/parsedatetime
	dev-python/python-dateutil
	dev-python/pyxdg
	dev-python/urwid
"
#RDEPEND="
#	${RDEPEND}
#"
BDEPEND="
	dev-python/setuptools-scm
	${DEPEND}
"
#	test? (
#		dev-python/freezegun
#		dev-python/hypothesis
#		dev-python/pytest
#		dev-python/pytz
#	)
#IUSE="test"
#distutils_enable_tests pytest

# FAILED tests/test_ui.py::test_todo_editor_list - AttributeError: 'bool' object has no attribute 'name'
# https://github.com/pimutils/todoman/issues/600
RESTRICT="test"

PATCHES=(
	"${FILESDIR}/specify-build-backend.patch"
	"${FILESDIR}/disable-test-coverage.patch"
)

# dev-python/sphinx-click is ::guru
distutils_enable_sphinx "docs/source" \
	dev-python/sphinx-click \
	dev-python/sphinx-rtd-theme

python_compile() {
	distutils-r1_python_compile
	if use doc; then
		sphinx_compile_all
		# i took this trick from python-utils-r1's build_sphinx
		${EPYTHON} -m sphinx.cmd.build -b man docs/source docs/build/man || die
	fi
	python_fix_shebang bin/todo
}

python_install() {
	distutils-r1_python_install
	if use doc; then
		doman docs/build/man/todo.1
	fi
	newbashcomp contrib/completion/bash/_todo todo
	# upstream says overwrite default todo binary for performance reasons
	# https://todoman.readthedocs.io/en/stable/install.html#:~:text=If%20your,one
	dobin "${S}/bin/todo"
}

python_test() {
	# https://github.com/pimutils/todoman/issues/404#issuecomment-643789777
	export TZ=UTC
	distutils-r1_python_test
}

pkg_postinst() {
	if ! use doc; then
		elog "Man pages require enabling the doc USE flag due to extra required dependencies."
		elog "One of the docs dependency is also only available in ::guru."
	fi
	optfeature "repl command support" dev-python/click-repl
}