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

EAPI=8

DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{10..14} )

inherit pypi distutils-r1 desktop xdg optfeature

DESCRIPTION="Stenography engine"
HOMEPAGE="https://opensteno.org/plover/"
SRC_URI="$(pypi_sdist_url "${PN}" "${PV}")"
S="${WORKDIR}/${P}"

# "or-later" is explicit, as part of README
LICENSE="GPL-2+"
SLOT="0"
KEYWORDS="~amd64"

# TODO: when opening paper tape:
#       _pythonToCppCopy: Cannot copy-convert 0x7f1755fa7920 (set) to C++.
#       _pythonToCppCopy: Cannot copy-convert 0x7f1755fa7920 (set) to C++.
#       _pythonToCppCopy: Cannot copy-convert 0x7f1755fa7920 (set) to C++.

# DEPEND sections:
# 1. dependencies
# 2. plover's own dependencies
# 3. see 2nd paragraph below
#
# dependencies sourced from reqs/dist.txt, as referenced in setup.py
# differences:
# - xkbcommon version requirement: ignored
# - readme-renderer: no USE flags, [md] removed
# - setuptools: implicit BDEPEND
#
# (this is for the 3th DEPEND section)
# dbus: https://github.com/opensteno/plover/blob/main/linux/README.md
# pyside: req/dist_extra_qt_gui.txt references pyside6-essentials, so
# probably pyside?
#
# some notes:
# - readme renderer: apparently used for plugins (XXX markdown via
#   packaging comrak (couldn't be packaged due to build system failing on
#   dependency resolution mysteriously))
#   /usr/lib/python3.14/site-packages/readme_renderer/markdown.py:44: UserWarning: Markdown renderers are not available. Install 'readme_renderer[md]' to enable Markdown rendering.
#   warnings.warn(_EXTRA_WARNING)
DEPEND="
	dev-python/appdirs
	dev-python/hidapi
	dev-python/pkginfo
	dev-python/pygments
	dev-python/pyserial
	dev-python/python-xlib
	dev-python/evdev
	dev-python/packaging
	dev-python/psutil
	dev-python/xkbcommon
	dev-python/readme-renderer
	dev-python/requests-cache
	dev-python/requests-futures
	dev-python/wcwidth

	dev-python/plover-stroke
	dev-python/rtf-tokenize

	sys-apps/dbus
	dev-python/pyside
"
RDEPEND="${DEPEND}"
# pyside tools: default ebuild setuptools makes something run
# /usr/lib/python3.14/site-packages/PySide6/Qt/libexec/uic, looks like a
# build dep for compiling .ui files
#
# babel: found by testing in minimal gentoo environment, used only in
# setup.py so is a build dependency
BDEPEND="
	dev-python/pyside[tools]
	dev-python/babel
"

EPYTEST_PLUGINS=(
	pytest-qt
)
# XXX: these tests get SIGABRT, but upstream CI is successful
EPYTEST_DESELECT=(
	"test/gui_qt/test_dictionaries_widget.py::test_widget_selection"
	"test/gui_qt/test_dictionaries_widget.py::test_widget_save_copy_1"
	"test/gui_qt/test_dictionaries_widget.py::test_widget_save_merge_1"
	"test/gui_qt/test_dictionaries_widget.py::test_widget_save_merge_2"
)
distutils_enable_tests pytest

# TODO: specialized hardware?
# TODO: extras, like gui_qt?
# TODO: uinput udev rule? (see appimage related stuff and
# https://github.com/opensteno/plover-flake#nixos-configuration and
# https://github.com/opensteno/plover/pull/1679)
# TODO: input group user?
# TODO: correct plugin info when viewing in the plugin viewer with installed
# plugins

python_install_all() {
	default
	domenu linux/plover.desktop
	doicon -s 128 plover/assets/plover.png
	newicon -s scalable plover/assets/plover-icon.svg plover.svg
}

pkg_postinst() {
	xdg_pkg_postinst
	# see plover source at plover/oslayer/linux/keyboardcontrol_uinput.py
	optfeature "Unicode input" app-i18n/ibus app-i18n/fcitx
	# https://plover.readthedocs.io/en/latest/plugin_dev.html
	elog "Because Plover plugins are basically Python modules, plugins must be"
	elog "installed by the system package manager (i.e. Portage), as system Python"
	elog "environment (where Plover checks) is handled by the system package manager."
	elog
	elog "Plover plugins are available under the \"plover-plugins\" category."
	elog "After installing, Plover must be restarted by quitting it (Ctrl+Q, or"
	elog "File > Quit Plover) and opening it again."
	elog
	elog "If there is a plugin you wish to use but is not packaged, please create a"
	elog "bug report for jacksonchen666's overlay on Sourcehut or Codeberg."
	elog "Sourcehut: https://todo.sr.ht/~jacksonchen666/gentoo-overlay"
	elog "Codeberg:  https://codeberg.org/jacksonchen666/gentoo-overlay/issues"
	elog "Note: Only plugins in the Plover plugin registry which isn't marked as"
	elog "unsupported will be added. Other stuff may be rejected."
	elog ""
	ewarn "Non-keyboard machines and input capture on Wayland may require"
	ewarn "additional configuration. Please bug report to this ebuild repository"
	ewarn "(not Plover!) if you're stuck, or found a solution."
}