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

EAPI=8

PYTHON_COMPAT=( python3_{9..12} )
DISTUTILS_SINGLE_IMPL=1

inherit distutils-r1 udev

DESCRIPTION="Drive Silhouette vinyl cutters from within inkscape."
HOMEPAGE="https://github.com/fablabnbg/inkscape-silhouette"

if [[ "${PV}" == "9999" ]]; then
	EGIT_REPO_URI="https://github.com/fablabnbg/${PN}.git"
	KEYWORDS=""
	inherit git-r3
else
	KEYWORDS="~amd64 ~x86"
	SRC_URI="https://github.com/fablabnbg/${PN}/archive/refs/tags/v${PV}.tar.gz"
fi

LICENSE="GPL-2"
SLOT="0"
IUSE=""

RESTRICT="test"

RDEPEND="
	>=media-gfx/inkscape-1.0
	dev-python/pyusb
"
DEPEND="${RDEPEND}"

DOCS=( Commands.md HISTORY.txt LICENSE README.md )
PATCHES=( "${FILESDIR}/${PN}-cleanup.patch" )

src_prepare() {
	default
	rm -r "${S}"/silhouette/pyusb-1.*
}

src_compile() {
	emake mo
}

src_install() {
	python_domodule silhouette

	DESTDIR="${D}" emake install
}

pkg_postinst() {
	udev_reload
}

pkg_postrm() {
	udev_reload
}