From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 096FC15821F for ; Sun, 24 Nov 2024 22:47:46 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 48AB2E0935 for ; Sun, 24 Nov 2024 22:47:36 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 1E5B9E07F1 for ; Sun, 24 Nov 2024 13:21:37 +0000 (UTC) Message-ID: Subject: Re: [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass From: =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?= To: "Anna (cybertailor) Vyalkova" , gentoo-guru@lists.gentoo.org Date: Sun, 24 Nov 2024 14:21:31 +0100 In-Reply-To: <20241123073302.24038-2-cyber+gentoo@sysrq.in> References: <20241123073302.24038-1-cyber+gentoo@sysrq.in> <20241123073302.24038-2-cyber+gentoo@sysrq.in> Organization: Gentoo Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-jwqQwP5a8YZVtEW/MeaP" User-Agent: Evolution 3.52.4 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Discussion on the GURU project and repository X-BeenThere: gentoo-guru@gentoo.org X-BeenThere: gentoo-guru@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 X-Archives-Salt: 7e887b53-f2e3-4b24-8dc8-518d6e1a35f8 X-Archives-Hash: 13b1d2a3769b2253d50c97988e0c4e7d --=-jwqQwP5a8YZVtEW/MeaP Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, 2024-11-23 at 12:27 +0500, Anna (cybertailor) Vyalkova wrote: > Signed-off-by: Anna (cybertailor) Vyalkova > --- > eclass/click-app.eclass | 162 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 162 insertions(+) > create mode 100644 eclass/click-app.eclass >=20 > diff --git a/eclass/click-app.eclass b/eclass/click-app.eclass > new file mode 100644 > index 000000000..0a75b9ea5 > --- /dev/null > +++ b/eclass/click-app.eclass > @@ -0,0 +1,162 @@ > +# Copyright 2024 Gentoo Authors > +# Distributed under the terms of the GNU General Public License v2 > + > +# @ECLASS: click-app.eclass > +# @MAINTAINER: > +# Anna > +# @AUTHOR: > +# Anna > +# @SUPPORTED_EAPIS: 8 > +# @BLURB: eclass for Click-based Python applications > +# @DESCRIPTION: > +# This eclass provides a streamlined way to generate and install shell > +# completions for Python applications based on the Click library > +# (dev-python/click package). > + > +case ${EAPI} in > + 8) ;; > + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; > +esac > + > +if [[ ! ${_CLICK_APP_ECLASS} ]]; then > +_CLICK_APP_ECLASS=3D1 > + > +inherit distutils-r1 shell-completion > + > +readonly _CLICK_COMPLETIONS_BUILD_DIR=3D"${WORKDIR}/${P}_click-shell-com= pletions" > + > +# @FUNCTION: click-app_enable_completions > +# @USAGE: > +# @DESCRIPTION: > +# Set up IUSE, BDEPEND, python_compile_all() and python_install_all() to > +# generate and install shell completions for the given scripts. > +# > +# This function does not overwrite python_compile_all() or python_instal= l_all() > +# if they are already defined (e.g. by distutils_enable_sphinx). You sh= ould call > +# click-app_python_compile_all or click-app_python_install_all in the > +# corresponding common phase functions in such cases. > +# > +# This function must be called in global scope. > +# > +# See also: https://click.palletsprojects.com/en/stable/shell-completion= / > +click-app_enable_completions() { > + debug-print-function "${FUNCNAME}" "${@}" > + (( $# >=3D 1 )) || > + die "${FUNCNAME} takes at least one argument" > + > + IUSE+=3D" bash-completion" > + BDEPEND+=3D" bash-completion? ( ${RDEPEND} )" > + > + _CLICK_SCRIPTS=3D() > + for script in "${@}"; do > + _CLICK_SCRIPTS+=3D( "${script}" ) > + done > + readonly -a _CLICK_SCRIPTS > + > + if ! declare -f python_compile_all; then > + python_compile_all() { click-app_python_compile_all; } > + fi > + > + if ! declare -f python_install_all; then > + python_install_all() { > + click-app_python_install_all > + distutils-r1_python_install_all > + } > + fi > + > + # we need to ensure successful return in case we're called last, > + # otherwise Portage may wrongly assume sourcing failed > + return 0 > +} > + > +# @FUNCTION: click-app_pkg_setup > +# @DESCRIPTION: > +# Ensure that only enabled Python implementations are used in python_...= _all > +# pseudo-phases when shell completions are to be built. > +click-app_pkg_setup() { > + debug-print-function "${FUNCNAME}" "${@}" > + use bash-completion || return 0 > + > + # If the package isn't built for a Python implementation that runs > + # python_compile_all(), we won't be able to call Python scripts from > + # its install tree. > + DISTUTILS_ALL_SUBPHASE_IMPLS=3D() > + for impl in "${PYTHON_COMPAT[@]}"; do > + use "python_targets_${impl}" && > + DISTUTILS_ALL_SUBPHASE_IMPLS+=3D( "${impl}" ) > + done > +} > + > +# @FUNCTION: click-app_python_compile_all > +# @DESCRIPTION: > +# Build shell completions for all scripts for which shell completions > +# were requested with click-app_enable_completions. > +click-app_python_compile_all() { > + debug-print-function "${FUNCNAME}" "${@}" > + use bash-completion || return 0 > + > + for script in "${_CLICK_SCRIPTS[@]}"; do > + build_click_completions "${script}" > + done > +} > + > +# @FUNCTION: click-app_python_install_all > +# @DESCRIPTION: > +# Install generated shell completions for all scripts for which shell > +# completions were requested with click-app_enable_completions. > +click-app_python_install_all() { > + debug-print-function "${FUNCNAME}" "${@}" > + use bash-completion || return 0 > + > + for script in "${_CLICK_SCRIPTS[@]}"; do > + install_click_completions "${script}" > + done > +} > + > +# @FUNCTION: build_click_completions > +# @USAGE: