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

EAPI=8

DISTUTILS_USE_PEP517=setuptools
DISTUTILS_SINGLE_IMPL=1
PYTHON_COMPAT=( python3_{11..14} )
inherit distutils-r1

DESCRIPTION="Create VCard, QR code, printable business cards with OpenPGP key and fingerprint"
HOMEPAGE="https://github.com/juga0/opgpcard"
SRC_URI="https://github.com/juga0/opgpcard/archive/v${PV}.tar.gz -> ${P}.gh.tar.gz"

LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64"
IUSE="doc examples"

RDEPEND="
	$(python_gen_cond_dep '
		>=dev-python/qrcode-5.3[${PYTHON_USEDEP}]
		>=dev-python/lxml-4.1[${PYTHON_USEDEP}]
		dev-python/gpgmepy[${PYTHON_USEDEP}]
	')
"
BDEPEND+=" doc? ( dev-python/sphinx )"

distutils_enable_tests pytest

PATCHES=("${FILESDIR}/0001-Fix-lxml-TypeError-5.patch")

python_compile_all() {
	if use doc; then
		pushd docs >/dev/null || die
		for format in html man text; do
			sphinx-build -b "$format" -d _build/doctrees source _build/"$format" || die
		done
		popd >/dev/null || die
		HTML_DOCS+=( "docs/_build/html/." )
	fi
}

python_install_all(){
	if use doc; then
		doman docs/_build/man/opgpcard.1
		dodoc -r docs/_build/text
	else
		doman "$FILESDIR"/opgpcard.1
	fi

	use examples && dodoc -r examples

	distutils-r1_python_install_all
}