From: "David Roman" <davidroman96@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] repo/proj/guru:master commit in: eclass/
Date: Wed, 27 Nov 2024 14:34:56 +0000 (UTC) [thread overview]
Message-ID: <1732630485.b46a0711d4d5f8b70721f96869f38bc8a8e4f229.davidroman@gentoo> (raw)
commit: b46a0711d4d5f8b70721f96869f38bc8a8e4f229
Author: Anna (cybertailor) Vyalkova <cyber+gentoo <AT> sysrq <DOT> in>
AuthorDate: Sat Nov 23 07:21:47 2024 +0000
Commit: David Roman <davidroman96 <AT> gmail <DOT> com>
CommitDate: Tue Nov 26 14:14:45 2024 +0000
URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=b46a0711
click-app.eclass: new eclass
Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo <AT> sysrq.in>
eclass/click-app.eclass | 129 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 129 insertions(+)
diff --git a/eclass/click-app.eclass b/eclass/click-app.eclass
new file mode 100644
index 000000000..d429e8128
--- /dev/null
+++ b/eclass/click-app.eclass
@@ -0,0 +1,129 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: click-app.eclass
+# @MAINTAINER:
+# Anna <cyber+gentoo@sysrq.in>
+# @AUTHOR:
+# Anna <cyber+gentoo@sysrq.in>
+# @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=1
+
+inherit distutils-r1 shell-completion
+
+# @FUNCTION: click-app_enable_completions
+# @USAGE: <script...>
+# @DESCRIPTION:
+# Set up IUSE, BDEPEND and python_install() to generate and install shell
+# completions for the given scripts.
+#
+# This function does not overwrite python_install() if it is already defined.
+# If you need to extend python_install(), you can call the original
+# implementation as click-app_python_install.
+#
+# 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}" "${@}"
+ (( $# >= 1 )) ||
+ die "${FUNCNAME} takes at least one argument"
+
+ IUSE+=" bash-completion"
+ BDEPEND+=" bash-completion? ( ${RDEPEND} )"
+
+ readonly -a _CLICK_SHELLCOMP_SCRIPTS=( "${@}" )
+
+ click-app_python_install() {
+ debug-print-function "${FUNCNAME}" "${@}"
+ use bash-completion || return 0
+
+ local script_name
+ for script_name in "${_CLICK_SHELLCOMP_SCRIPTS[@]?}"; do
+ click_install_completions "${script_name:?}"
+ done
+ }
+
+ if ! declare -f python_install; then
+ python_install() {
+ click-app_python_install
+ distutils-r1_python_install
+ }
+ 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_python_install
+# @USAGE: <script...>
+# @DESCRIPTION:
+# Generate and install shell completions for the given scripts.
+#
+# Note that this function checks if USE="bash-completion" is enabled, and if
+# not automatically exits. Therefore, there is no need to wrap this function
+# in an "if" statement.
+#
+# This function needs to be called before distutils-r1_python_install.
+
+# @FUNCTION: click_install_completions
+# @USAGE: <script>
+# @DESCRIPTION:
+# Generate and install shell completions for a single script.
+#
+# Note that if a shell completions directory already exists in the install tree,
+# generation and installation steps will be skipped for this shell.
+#
+# This function needs to be called before distutils-r1_python_install.
+click_install_completions() {
+ debug-print-function "${FUNCNAME}" "${@}"
+ (( $# == 1 )) ||
+ die "${FUNCNAME} takes exactly one argument"
+
+ _gen_click_completions() {
+ local shell=${1:?}
+
+ echo "${env_var_name:?}=${shell:?}_source ${script_path:?}" >&2
+ local -x "${env_var_name:?}"="${shell:?}_source" || die
+ "${script_path:?}" || die
+ }
+
+ local env_var_name script_name script_path
+
+ script_name=${1:?}
+ script_path="${BUILD_DIR}/install${EPREFIX}/usr/bin/${script_name:?}"
+ [[ -f "${script_path}" ]] ||
+ die "${script_path} not found, click_install_completions call wrong"
+
+ # convert to screaming snake case
+ env_var_name="_${script_name:?}_COMPLETE"
+ env_var_name=${env_var_name^^}
+ env_var_name=${env_var_name//-/_}
+
+ if [[ ! -d "${D}/$(get_bashcompdir)" ]]; then
+ _gen_click_completions bash | newbashcomp - "${script_name:?}"
+ fi
+ if [[ ! -d "${D}/$(get_fishcompdir)" ]]; then
+ _gen_click_completions fish | newfishcomp - "${script_name:?}.fish"
+ fi
+ if [[ ! -d "${D}/$(get_zshcompdir)" ]]; then
+ _gen_click_completions zsh | newzshcomp - "_${script_name:?}"
+ fi
+
+ unset -f _gen_click_completions
+}
+
+fi
next reply other threads:[~2024-11-27 14:35 UTC|newest]
Thread overview: 108+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-27 14:34 David Roman [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-10-20 14:06 [gentoo-commits] repo/proj/guru:master commit in: eclass/ David Roman
2024-10-19 0:05 David Roman
2024-07-14 17:47 [gentoo-commits] repo/proj/guru:dev " Florian Schmaus
2024-07-14 17:47 ` [gentoo-commits] repo/proj/guru:master " Florian Schmaus
2024-07-14 15:27 Haelwenn Monnier
2024-07-14 15:27 Haelwenn Monnier
2024-07-14 15:27 Haelwenn Monnier
2024-07-14 15:27 Haelwenn Monnier
2024-07-14 15:27 Haelwenn Monnier
2024-07-14 15:27 Haelwenn Monnier
2024-07-14 15:27 Haelwenn Monnier
2024-07-01 13:50 David Roman
2024-04-27 11:10 David Roman
2024-04-01 11:32 Julien Roy
2024-03-31 17:57 Julien Roy
2024-03-31 17:49 [gentoo-commits] repo/proj/guru:dev " Julien Roy
2024-03-31 17:57 ` [gentoo-commits] repo/proj/guru:master " Julien Roy
2024-02-05 11:57 David Roman
2024-02-05 11:57 David Roman
2024-02-05 11:57 David Roman
2024-02-05 11:57 David Roman
2024-01-20 22:13 David Roman
2024-01-03 15:20 David Roman
2023-10-05 14:25 Viorel Munteanu
2023-10-05 6:18 Viorel Munteanu
2023-08-30 5:30 [gentoo-commits] repo/proj/guru:dev " Viorel Munteanu
2023-08-30 5:36 ` [gentoo-commits] repo/proj/guru:master " Viorel Munteanu
2023-08-07 12:51 David Roman
2023-08-07 12:51 David Roman
2023-08-04 7:26 [gentoo-commits] repo/proj/guru:dev " Florian Schmaus
2023-08-04 7:26 ` [gentoo-commits] repo/proj/guru:master " Florian Schmaus
2023-08-04 7:26 [gentoo-commits] repo/proj/guru:dev " Florian Schmaus
2023-08-04 7:26 ` [gentoo-commits] repo/proj/guru:master " Florian Schmaus
2023-07-17 14:24 Florian Schmaus
2023-06-26 11:24 Andrew Ammerlaan
2023-05-22 5:17 Viorel Munteanu
2023-05-22 5:17 Viorel Munteanu
2023-05-11 14:32 Andrew Ammerlaan
2023-05-11 14:32 Andrew Ammerlaan
2023-05-11 14:32 Andrew Ammerlaan
2023-05-11 14:32 Andrew Ammerlaan
2023-05-11 14:32 Andrew Ammerlaan
2023-04-13 7:02 Florian Schmaus
2023-04-01 21:30 Haelwenn Monnier
2023-04-01 21:30 Haelwenn Monnier
2023-04-01 21:30 Haelwenn Monnier
2023-02-27 15:06 Florian Schmaus
2023-02-27 15:06 Florian Schmaus
2023-01-08 10:27 Florian Schmaus
2022-12-09 16:26 Ronny Gutbrod
2022-11-26 10:54 Florian Schmaus
2022-11-26 10:54 Florian Schmaus
2022-11-26 10:54 Florian Schmaus
2022-11-26 10:54 Florian Schmaus
2022-11-26 10:54 Florian Schmaus
2022-11-26 10:54 Florian Schmaus
2022-11-26 10:54 Florian Schmaus
2022-11-26 10:54 Florian Schmaus
2022-11-26 10:54 Florian Schmaus
2022-11-26 10:54 Florian Schmaus
2022-11-26 10:54 Florian Schmaus
2022-11-16 19:33 Florian Schmaus
2022-11-16 19:33 Florian Schmaus
2022-11-16 19:33 Florian Schmaus
2022-11-05 15:26 Arthur Zamarin
2022-07-20 9:35 Andrew Ammerlaan
2022-07-20 9:35 Andrew Ammerlaan
2022-07-20 9:35 Andrew Ammerlaan
2022-07-20 9:35 Andrew Ammerlaan
2022-07-20 9:35 Andrew Ammerlaan
2022-07-11 6:54 Andrew Ammerlaan
2022-06-30 17:39 Florian Schmaus
2022-06-29 15:38 Florian Schmaus
2022-06-29 15:38 Florian Schmaus
2022-06-14 18:35 Haelwenn Monnier
2022-06-14 18:35 Haelwenn Monnier
2022-06-14 18:35 Haelwenn Monnier
2022-05-12 9:14 Andrew Ammerlaan
2022-05-05 14:42 Haelwenn Monnier
2022-05-05 14:42 Haelwenn Monnier
2022-05-05 14:42 Haelwenn Monnier
2022-04-15 20:58 Haelwenn Monnier
2022-04-15 20:58 Haelwenn Monnier
2022-04-14 13:31 Andrew Ammerlaan
2022-04-12 19:35 Ronny Gutbrod
2022-04-12 19:35 Ronny Gutbrod
2022-04-12 19:35 Ronny Gutbrod
2022-02-20 8:46 Florian Schmaus
2022-02-20 8:46 Florian Schmaus
2021-10-06 1:13 Theo Anderson
2021-09-30 19:39 Arthur Zamarin
2021-09-08 15:20 Arthur Zamarin
2021-07-26 14:05 Andrew Ammerlaan
2021-06-02 16:00 Andrew Ammerlaan
2021-05-24 22:25 Haelwenn Monnier
2021-05-17 19:11 Andrew Ammerlaan
2021-03-16 10:49 Andrew Ammerlaan
2021-03-15 10:58 Andrew Ammerlaan
2021-03-15 10:58 Andrew Ammerlaan
2020-12-06 10:46 [gentoo-commits] repo/proj/guru:dev " Andrew Ammerlaan
2020-12-06 10:49 ` [gentoo-commits] repo/proj/guru:master " Andrew Ammerlaan
2020-05-07 11:13 Andrew Ammerlaan
2020-05-07 11:13 Andrew Ammerlaan
2020-05-01 15:39 Andrew Ammerlaan
2020-04-28 8:01 Andrew Ammerlaan
2020-04-28 7:44 Andrew Ammerlaan
2020-04-21 10:23 Andrew Ammerlaan
2020-04-21 10:20 Andrew Ammerlaan
2020-04-07 7:42 Andrew Ammerlaan
2020-04-07 7:42 Andrew Ammerlaan
2020-04-07 7:27 [gentoo-commits] repo/proj/guru:dev " Andrew Ammerlaan
2020-04-07 7:42 ` [gentoo-commits] repo/proj/guru:master " Andrew Ammerlaan
2020-04-07 7:16 [gentoo-commits] repo/proj/guru:dev " Andrew Ammerlaan
2020-04-07 7:42 ` [gentoo-commits] repo/proj/guru:master " Andrew Ammerlaan
2020-04-06 18:26 [gentoo-commits] repo/proj/guru:dev " Andrew Ammerlaan
2020-04-07 7:42 ` [gentoo-commits] repo/proj/guru:master " Andrew Ammerlaan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1732630485.b46a0711d4d5f8b70721f96869f38bc8a8e4f229.davidroman@gentoo \
--to=davidroman96@gmail.com \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox