# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI=8
DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python{3_8,3_9,3_10} )

inherit distutils-r1

DESCRIPTION="A CMS to generate a static websites"
HOMEPAGE="https://www.getlektor.com/"
SRC_URI="https://github.com/${PN}/${PN}/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="AGPL-3"
SLOT="0"
KEYWORDS="amd64 x86"
IUSE="examples"

DEPEND="media-gfx/imagemagick
	net-libs/nodejs[npm]
	dev-python/Babel[${PYTHON_USEDEP}]
	dev-python/click[${PYTHON_USEDEP}]
	dev-python/exifread[${PYTHON_USEDEP}]
	dev-python/filetype[${PYTHON_USEDEP}]
	dev-python/flask[${PYTHON_USEDEP}]
	dev-python/jinja[${PYTHON_USEDEP}]
	<dev-python/mistune-1.0[${PYTHON_USEDEP}]
	dev-python/pip[${PYTHON_USEDEP}]
	dev-python/python-inifile[${PYTHON_USEDEP}]
	dev-python/requests[${PYTHON_USEDEP}]
	dev-python/python-slugify[${PYTHON_USEDEP}]
	dev-python/watchdog[${PYTHON_USEDEP}]"
RDEPEND=""

DOCS=( CHANGES.md README.md )

pkg_setup() {
        if [[ ${PV} != 9999 ]]; then
                export SETUPTOOLS_SCM_PRETEND_VERSION="${PV}"
        fi
}

src_prepare() {
	default

	# unpack static webcontent, pre-compiled with (as root):
	# ebuild ${P}.ebuild unpack
	# cd /var/tmp/portage/www-apps/${P}/work/${P}
	# su -s /bin/bash -c "make build-js" portage
	# tar cfvz /tmp/${PN}-static-${PV}.tar.gz lektor/admin/static
	unpack ${FILESDIR}/${PN}-static-${PV}.tar.gz

	epatch ${FILESDIR}/pip-install-user-${PV}.patch
}

python_install_all() {
	if use examples; then
		insinto "/usr/share/doc/${PF}"
		docompress -x "/usr/share/doc/${PF}/example"
		doins -r example
	fi
	distutils-r1_python_install_all
}
