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

EAPI=8

DISTUTILS_EXT=1
DISTUTILS_USE_PEP517=no
PYTHON_COMPAT=( python3_{10..13} pypy3 )

inherit meson distutils-r1

DESCRIPTION="Backend-agnostic network configuration in YAML"
HOMEPAGE="https://netplan.io/"
SRC_URI="https://github.com/CanonicalLtd/${PN}/archive/${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="GPL-3"
SLOT="0"

KEYWORDS="~amd64"

IUSE="examples +systemd +bash-completion test lto"
REQUIRED_USE="systemd bash-completion"

DEPEND=">=dev-libs/glib-2.64.3
        >=dev-libs/libyaml-0.2.5
        sys-apps/util-linux
        doc? ( >=app-text/pandoc-1.19.2.1-r1 )
"

BDEPEND="${DEPEND}
         dev-python/pytest
         dev-python/pyflakes
         dev-python/coverage
         dev-python/jaraco-text
         test? ( dev-util/cmocka
                 dev-python/pycodestyle
               )
"

RDEPEND=">=dev-python/netifaces-0.10.9
         >=dev-libs/libyaml-0.2.5
         >=dev-python/pyyaml-5.3.1
         dev-python/rich
         sys-apps/systemd
         app-shells/bash-completion
"

PATCHES=(
        "${FILESDIR}/0001-build-add-Gentoo-compat.patch"
)

distutils_enable_sphinx doc

python_configure() {
        local emesonargs=(
                $(meson_use test unit_testing)
                $(meson_use test b_coverage)
                $(meson_use lto b_lto)
        )
        meson_src_configure
}

python_compile() {
        meson_src_compile
}

python_install() {
        meson_src_install
        python_optimize
}

python_install_all() {
        distutils-r1_python_install_all
        
        if use examples; then
            dodoc -r examples
        fi
        
        rm -rf "${D}"/usr/share/doc/netplan
}
