public inbox for gentoo-guru@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-guru] [0/2] new eclass: click-app; generate and install shell completions
@ 2024-11-23  7:27 Anna (cybertailor) Vyalkova
  2024-11-23  7:27 ` [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass Anna (cybertailor) Vyalkova
  2024-11-23  7:27 ` [gentoo-guru] [PATCH 2/2] dev-util/bump-my-version: add completions support Anna (cybertailor) Vyalkova
  0 siblings, 2 replies; 8+ messages in thread
From: Anna (cybertailor) Vyalkova @ 2024-11-23  7:27 UTC (permalink / raw
  To: gentoo-guru

In most cases it'll be enough to inherit the eclass and call
"click-app_enable_completions my-app".

as proposed in:
https://public-inbox.gentoo.org/gentoo-dev/Zz9Ecm48T6vnsZ65@sysrq.in


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass
  2024-11-23  7:27 [gentoo-guru] [0/2] new eclass: click-app; generate and install shell completions Anna (cybertailor) Vyalkova
@ 2024-11-23  7:27 ` Anna (cybertailor) Vyalkova
  2024-11-24 13:00   ` Takuya Wakazono
  2024-11-24 13:21   ` Michał Górny
  2024-11-23  7:27 ` [gentoo-guru] [PATCH 2/2] dev-util/bump-my-version: add completions support Anna (cybertailor) Vyalkova
  1 sibling, 2 replies; 8+ messages in thread
From: Anna (cybertailor) Vyalkova @ 2024-11-23  7:27 UTC (permalink / raw
  To: gentoo-guru

Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo@sysrq.in>
---
 eclass/click-app.eclass | 162 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 162 insertions(+)
 create mode 100644 eclass/click-app.eclass

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 <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
+
+readonly _CLICK_COMPLETIONS_BUILD_DIR="${WORKDIR}/${P}_click-shell-completions"
+
+# @FUNCTION: click-app_enable_completions
+# @USAGE: <script...>
+# @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_install_all()
+# if they are already defined (e.g. by distutils_enable_sphinx).  You should 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}" "${@}"
+	(( $# >= 1 )) ||
+		die "${FUNCNAME} takes at least one argument"
+
+	IUSE+=" bash-completion"
+	BDEPEND+=" bash-completion? ( ${RDEPEND} )"
+
+	_CLICK_SCRIPTS=()
+	for script in "${@}"; do
+		_CLICK_SCRIPTS+=( "${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=()
+	for impl in "${PYTHON_COMPAT[@]}"; do
+		use "python_targets_${impl}" &&
+			DISTUTILS_ALL_SUBPHASE_IMPLS+=( "${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: <script>
+# @DESCRIPTION:
+# Build shell completions for a script.
+build_click_completions() {
+	debug-print-function "${FUNCNAME}" "${@}"
+	(( $# == 1 )) ||
+		die "${FUNCNAME} takes exactly one argument"
+
+	local env_var_name out_path script_path t
+
+	script_path="${BUILD_DIR}/install${EPREFIX}/usr/bin/${1}"
+	[[ -f "${script_path}" ]] ||
+		die "${script_path} not found, build_click_completions call wrong"
+
+	# convert to screaming snake case
+	t=${1^^}
+	t=${t//-/_}
+	env_var_name="_${t}_COMPLETE"
+
+	mkdir -p "${_CLICK_COMPLETIONS_BUILD_DIR}" || die
+	for shell in bash fish zsh; do
+		out_path="${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.${shell}"
+
+		echo "${env_var_name}=${shell}_source ${script_path} > ${out_path}" >&2
+		local -x "${env_var_name}"="${shell}_source" || die
+		"${script_path}" > "${out_path}" || die
+	done
+}
+
+# @FUNCTION: install_click_completions
+# @USAGE: <script>
+# @DESCRIPTION:
+# Install generated shell completions for a script.
+install_click_completions() {
+	debug-print-function "${FUNCNAME}" "${@}"
+	(( $# == 1 )) ||
+		die "${FUNCNAME} takes exactly one argument"
+
+	newbashcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.bash" "${1}"
+	newfishcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.fish" "${1}.fish"
+	newzshcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.zsh" "_${1}"
+}
+
+fi
+
+EXPORT_FUNCTIONS pkg_setup
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-guru] [PATCH 2/2] dev-util/bump-my-version: add completions support
  2024-11-23  7:27 [gentoo-guru] [0/2] new eclass: click-app; generate and install shell completions Anna (cybertailor) Vyalkova
  2024-11-23  7:27 ` [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass Anna (cybertailor) Vyalkova
@ 2024-11-23  7:27 ` Anna (cybertailor) Vyalkova
  1 sibling, 0 replies; 8+ messages in thread
From: Anna (cybertailor) Vyalkova @ 2024-11-23  7:27 UTC (permalink / raw
  To: gentoo-guru

Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo@sysrq.in>
---
 dev-util/bump-my-version/bump-my-version-0.28.1.ebuild | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/dev-util/bump-my-version/bump-my-version-0.28.1.ebuild b/dev-util/bump-my-version/bump-my-version-0.28.1.ebuild
index 6d418372d..f80e2375d 100644
--- a/dev-util/bump-my-version/bump-my-version-0.28.1.ebuild
+++ b/dev-util/bump-my-version/bump-my-version-0.28.1.ebuild
@@ -5,7 +5,7 @@ EAPI=8
 
 DISTUTILS_USE_PEP517=hatchling
 PYTHON_COMPAT=( python3_{11..13} )
-inherit distutils-r1 pypi
+inherit click-app distutils-r1 pypi
 
 DESCRIPTION="Version bump your Python project"
 HOMEPAGE="
@@ -40,6 +40,8 @@ DOCS=( {CHANGELOG,CODE_OF_CONDUCT,CONTRIBUTING,README}.md )
 
 distutils_enable_tests pytest
 
+click-app_enable_completions bump-my-version
+
 python_test() {
 	epytest -o "addopts="
 }
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass
  2024-11-23  7:27 ` [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass Anna (cybertailor) Vyalkova
@ 2024-11-24 13:00   ` Takuya Wakazono
  2024-11-24 14:30     ` Anna (cybertailor) Vyalkova
  2024-11-24 13:21   ` Michał Górny
  1 sibling, 1 reply; 8+ messages in thread
From: Takuya Wakazono @ 2024-11-24 13:00 UTC (permalink / raw
  To: Anna (cybertailor) Vyalkova; +Cc: gentoo-guru

On Sat, Nov 23, 2024 at 4:33 PM Anna (cybertailor) Vyalkova
<cyber+gentoo@sysrq.in> wrote:
>
> Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo@sysrq.in>
> ---
>  eclass/click-app.eclass | 162 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 162 insertions(+)
>  create mode 100644 eclass/click-app.eclass
>
> 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 <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
> +
> +readonly _CLICK_COMPLETIONS_BUILD_DIR="${WORKDIR}/${P}_click-shell-completions"
> +
> +# @FUNCTION: click-app_enable_completions
> +# @USAGE: <script...>
> +# @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_install_all()
> +# if they are already defined (e.g. by distutils_enable_sphinx).  You should 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}" "${@}"
> +       (( $# >= 1 )) ||
> +               die "${FUNCNAME} takes at least one argument"
> +
> +       IUSE+=" bash-completion"
> +       BDEPEND+=" bash-completion? ( ${RDEPEND} )"
How about 'shell-completion'? 'bash-completion' controlling fish and zsh
completion files feels unintuitive.

> +
> +       _CLICK_SCRIPTS=()
> +       for script in "${@}"; do
> +               _CLICK_SCRIPTS+=( "${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=()
> +       for impl in "${PYTHON_COMPAT[@]}"; do
> +               use "python_targets_${impl}" &&
> +                       DISTUTILS_ALL_SUBPHASE_IMPLS+=( "${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: <script>
> +# @DESCRIPTION:
> +# Build shell completions for a script.
> +build_click_completions() {
> +       debug-print-function "${FUNCNAME}" "${@}"
> +       (( $# == 1 )) ||
> +               die "${FUNCNAME} takes exactly one argument"
> +
> +       local env_var_name out_path script_path t
> +
> +       script_path="${BUILD_DIR}/install${EPREFIX}/usr/bin/${1}"
> +       [[ -f "${script_path}" ]] ||
> +               die "${script_path} not found, build_click_completions call wrong"
> +
> +       # convert to screaming snake case
> +       t=${1^^}
> +       t=${t//-/_}
> +       env_var_name="_${t}_COMPLETE"
> +
> +       mkdir -p "${_CLICK_COMPLETIONS_BUILD_DIR}" || die
> +       for shell in bash fish zsh; do
> +               out_path="${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.${shell}"
> +
> +               echo "${env_var_name}=${shell}_source ${script_path} > ${out_path}" >&2
> +               local -x "${env_var_name}"="${shell}_source" || die
> +               "${script_path}" > "${out_path}" || die
> +       done
> +}
> +
> +# @FUNCTION: install_click_completions
> +# @USAGE: <script>
> +# @DESCRIPTION:
> +# Install generated shell completions for a script.
> +install_click_completions() {
> +       debug-print-function "${FUNCNAME}" "${@}"
> +       (( $# == 1 )) ||
> +               die "${FUNCNAME} takes exactly one argument"
> +
> +       newbashcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.bash" "${1}"
> +       newfishcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.fish" "${1}.fish"
> +       newzshcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.zsh" "_${1}"
> +}
> +
> +fi
> +
> +EXPORT_FUNCTIONS pkg_setup
> --
> 2.47.0
>
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass
  2024-11-23  7:27 ` [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass Anna (cybertailor) Vyalkova
  2024-11-24 13:00   ` Takuya Wakazono
@ 2024-11-24 13:21   ` Michał Górny
  2024-11-24 14:46     ` Anna (cybertailor) Vyalkova
  1 sibling, 1 reply; 8+ messages in thread
From: Michał Górny @ 2024-11-24 13:21 UTC (permalink / raw
  To: Anna (cybertailor) Vyalkova, gentoo-guru

[-- Attachment #1: Type: text/plain, Size: 6217 bytes --]

On Sat, 2024-11-23 at 12:27 +0500, Anna (cybertailor) Vyalkova wrote:
> Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo@sysrq.in>
> ---
>  eclass/click-app.eclass | 162 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 162 insertions(+)
>  create mode 100644 eclass/click-app.eclass
> 
> 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 <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
> +
> +readonly _CLICK_COMPLETIONS_BUILD_DIR="${WORKDIR}/${P}_click-shell-completions"
> +
> +# @FUNCTION: click-app_enable_completions
> +# @USAGE: <script...>
> +# @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_install_all()
> +# if they are already defined (e.g. by distutils_enable_sphinx).  You should 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}" "${@}"
> +	(( $# >= 1 )) ||
> +		die "${FUNCNAME} takes at least one argument"
> +
> +	IUSE+=" bash-completion"
> +	BDEPEND+=" bash-completion? ( ${RDEPEND} )"
> +
> +	_CLICK_SCRIPTS=()
> +	for script in "${@}"; do
> +		_CLICK_SCRIPTS+=( "${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=()
> +	for impl in "${PYTHON_COMPAT[@]}"; do
> +		use "python_targets_${impl}" &&
> +			DISTUTILS_ALL_SUBPHASE_IMPLS+=( "${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: <script>
> +# @DESCRIPTION:
> +# Build shell completions for a script.
> +build_click_completions() {
> +	debug-print-function "${FUNCNAME}" "${@}"
> +	(( $# == 1 )) ||
> +		die "${FUNCNAME} takes exactly one argument"
> +
> +	local env_var_name out_path script_path t
> +
> +	script_path="${BUILD_DIR}/install${EPREFIX}/usr/bin/${1}"
> +	[[ -f "${script_path}" ]] ||
> +		die "${script_path} not found, build_click_completions call wrong"
> +
> +	# convert to screaming snake case
> +	t=${1^^}
> +	t=${t//-/_}
> +	env_var_name="_${t}_COMPLETE"
> +
> +	mkdir -p "${_CLICK_COMPLETIONS_BUILD_DIR}" || die
> +	for shell in bash fish zsh; do
> +		out_path="${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.${shell}"
> +
> +		echo "${env_var_name}=${shell}_source ${script_path} > ${out_path}" >&2
> +		local -x "${env_var_name}"="${shell}_source" || die
> +		"${script_path}" > "${out_path}" || die
> +	done
> +}
> +
> +# @FUNCTION: install_click_completions
> +# @USAGE: <script>
> +# @DESCRIPTION:
> +# Install generated shell completions for a script.
> +install_click_completions() {
> +	debug-print-function "${FUNCNAME}" "${@}"
> +	(( $# == 1 )) ||
> +		die "${FUNCNAME} takes exactly one argument"
> +
> +	newbashcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.bash" "${1}"
> +	newfishcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.fish" "${1}.fish"
> +	newzshcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.zsh" "_${1}"
> +}
> +
> +fi
> +
> +EXPORT_FUNCTIONS pkg_setup

That sounds like a lot of complexity for something that could be more
cleanly achieved by a single function called from python_install()
(and detecting that it's been called already by existing completions).

-- 
Best regards,
Michał Górny


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 512 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass
  2024-11-24 13:00   ` Takuya Wakazono
@ 2024-11-24 14:30     ` Anna (cybertailor) Vyalkova
  0 siblings, 0 replies; 8+ messages in thread
From: Anna (cybertailor) Vyalkova @ 2024-11-24 14:30 UTC (permalink / raw
  To: gentoo-guru

On 2024-11-24 22:00, Takuya Wakazono wrote:
>On Sat, Nov 23, 2024 at 4:33 PM Anna (cybertailor) Vyalkova
><cyber+gentoo@sysrq.in> wrote:
>>
>> Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo@sysrq.in>
>> ---
>>  eclass/click-app.eclass | 162 ++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 162 insertions(+)
>>  create mode 100644 eclass/click-app.eclass
>>
>> 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 <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
>> +
>> +readonly _CLICK_COMPLETIONS_BUILD_DIR="${WORKDIR}/${P}_click-shell-completions"
>> +
>> +# @FUNCTION: click-app_enable_completions
>> +# @USAGE: <script...>
>> +# @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_install_all()
>> +# if they are already defined (e.g. by distutils_enable_sphinx).  You should 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}" "${@}"
>> +       (( $# >= 1 )) ||
>> +               die "${FUNCNAME} takes at least one argument"
>> +
>> +       IUSE+=" bash-completion"
>> +       BDEPEND+=" bash-completion? ( ${RDEPEND} )"
>How about 'shell-completion'? 'bash-completion' controlling fish and zsh
>completion files feels unintuitive.

Thanks for asking.

Yes, this is unintuitive. However 'bash-completion' is a global USE flag 
that doesn't need to be explicitly stated in 'metadata.xml' of every 
package that uses it.

If there was a more generic global USE flag for shell completions, I'd 
have used it.

>> +
>> +       _CLICK_SCRIPTS=()
>> +       for script in "${@}"; do
>> +               _CLICK_SCRIPTS+=( "${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=()
>> +       for impl in "${PYTHON_COMPAT[@]}"; do
>> +               use "python_targets_${impl}" &&
>> +                       DISTUTILS_ALL_SUBPHASE_IMPLS+=( "${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: <script>
>> +# @DESCRIPTION:
>> +# Build shell completions for a script.
>> +build_click_completions() {
>> +       debug-print-function "${FUNCNAME}" "${@}"
>> +       (( $# == 1 )) ||
>> +               die "${FUNCNAME} takes exactly one argument"
>> +
>> +       local env_var_name out_path script_path t
>> +
>> +       script_path="${BUILD_DIR}/install${EPREFIX}/usr/bin/${1}"
>> +       [[ -f "${script_path}" ]] ||
>> +               die "${script_path} not found, build_click_completions call wrong"
>> +
>> +       # convert to screaming snake case
>> +       t=${1^^}
>> +       t=${t//-/_}
>> +       env_var_name="_${t}_COMPLETE"
>> +
>> +       mkdir -p "${_CLICK_COMPLETIONS_BUILD_DIR}" || die
>> +       for shell in bash fish zsh; do
>> +               out_path="${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.${shell}"
>> +
>> +               echo "${env_var_name}=${shell}_source ${script_path} > ${out_path}" >&2
>> +               local -x "${env_var_name}"="${shell}_source" || die
>> +               "${script_path}" > "${out_path}" || die
>> +       done
>> +}
>> +
>> +# @FUNCTION: install_click_completions
>> +# @USAGE: <script>
>> +# @DESCRIPTION:
>> +# Install generated shell completions for a script.
>> +install_click_completions() {
>> +       debug-print-function "${FUNCNAME}" "${@}"
>> +       (( $# == 1 )) ||
>> +               die "${FUNCNAME} takes exactly one argument"
>> +
>> +       newbashcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.bash" "${1}"
>> +       newfishcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.fish" "${1}.fish"
>> +       newzshcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.zsh" "_${1}"
>> +}
>> +
>> +fi
>> +
>> +EXPORT_FUNCTIONS pkg_setup
>> --
>> 2.47.0
>>
>>
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass
  2024-11-24 13:21   ` Michał Górny
@ 2024-11-24 14:46     ` Anna (cybertailor) Vyalkova
  2024-11-24 15:26       ` Michał Górny
  0 siblings, 1 reply; 8+ messages in thread
From: Anna (cybertailor) Vyalkova @ 2024-11-24 14:46 UTC (permalink / raw
  To: gentoo-guru

On 2024-11-24 14:21, Michał Górny wrote:
>On Sat, 2024-11-23 at 12:27 +0500, Anna (cybertailor) Vyalkova wrote:
>> Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo@sysrq.in>
>> ---
>>  eclass/click-app.eclass | 162 ++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 162 insertions(+)
>>  create mode 100644 eclass/click-app.eclass
>>
>> 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 <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
>> +
>> +readonly _CLICK_COMPLETIONS_BUILD_DIR="${WORKDIR}/${P}_click-shell-completions"
>> +
>> +# @FUNCTION: click-app_enable_completions
>> +# @USAGE: <script...>
>> +# @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_install_all()
>> +# if they are already defined (e.g. by distutils_enable_sphinx).  You should 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}" "${@}"
>> +	(( $# >= 1 )) ||
>> +		die "${FUNCNAME} takes at least one argument"
>> +
>> +	IUSE+=" bash-completion"
>> +	BDEPEND+=" bash-completion? ( ${RDEPEND} )"
>> +
>> +	_CLICK_SCRIPTS=()
>> +	for script in "${@}"; do
>> +		_CLICK_SCRIPTS+=( "${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=()
>> +	for impl in "${PYTHON_COMPAT[@]}"; do
>> +		use "python_targets_${impl}" &&
>> +			DISTUTILS_ALL_SUBPHASE_IMPLS+=( "${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: <script>
>> +# @DESCRIPTION:
>> +# Build shell completions for a script.
>> +build_click_completions() {
>> +	debug-print-function "${FUNCNAME}" "${@}"
>> +	(( $# == 1 )) ||
>> +		die "${FUNCNAME} takes exactly one argument"
>> +
>> +	local env_var_name out_path script_path t
>> +
>> +	script_path="${BUILD_DIR}/install${EPREFIX}/usr/bin/${1}"
>> +	[[ -f "${script_path}" ]] ||
>> +		die "${script_path} not found, build_click_completions call wrong"
>> +
>> +	# convert to screaming snake case
>> +	t=${1^^}
>> +	t=${t//-/_}
>> +	env_var_name="_${t}_COMPLETE"
>> +
>> +	mkdir -p "${_CLICK_COMPLETIONS_BUILD_DIR}" || die
>> +	for shell in bash fish zsh; do
>> +		out_path="${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.${shell}"
>> +
>> +		echo "${env_var_name}=${shell}_source ${script_path} > ${out_path}" >&2
>> +		local -x "${env_var_name}"="${shell}_source" || die
>> +		"${script_path}" > "${out_path}" || die
>> +	done
>> +}
>> +
>> +# @FUNCTION: install_click_completions
>> +# @USAGE: <script>
>> +# @DESCRIPTION:
>> +# Install generated shell completions for a script.
>> +install_click_completions() {
>> +	debug-print-function "${FUNCNAME}" "${@}"
>> +	(( $# == 1 )) ||
>> +		die "${FUNCNAME} takes exactly one argument"
>> +
>> +	newbashcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.bash" "${1}"
>> +	newfishcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.fish" "${1}.fish"
>> +	newzshcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.zsh" "_${1}"
>> +}
>> +
>> +fi
>> +
>> +EXPORT_FUNCTIONS pkg_setup
>
>That sounds like a lot of complexity for something that could be more
>cleanly achieved by a single function called from python_install()
>(and detecting that it's been called already by existing completions).

Ohh, this haven't even crossed my mind, thanks.

It works (when called before 'distutils-r1_python_install') and makes 
'python_compile_all()' subphase unnecessary. Setting BDEPEND is still 
necessary as build and running environments can be different, if I 
understand correctly, but 'pkg_setup()' phase can be removed too.

Moreover, it could work without creating temporary files by piping 
straightly to 'newins -'. However checking $PIPESTATUS might be needed 
in such case.

>
>-- 
>Best regards,
>Michał Górny
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass
  2024-11-24 14:46     ` Anna (cybertailor) Vyalkova
@ 2024-11-24 15:26       ` Michał Górny
  0 siblings, 0 replies; 8+ messages in thread
From: Michał Górny @ 2024-11-24 15:26 UTC (permalink / raw
  To: gentoo-guru

[-- Attachment #1: Type: text/plain, Size: 7717 bytes --]

On Sun, 2024-11-24 at 19:46 +0500, Anna (cybertailor) Vyalkova wrote:
> On 2024-11-24 14:21, Michał Górny wrote:
> > On Sat, 2024-11-23 at 12:27 +0500, Anna (cybertailor) Vyalkova wrote:
> > > Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo@sysrq.in>
> > > ---
> > >  eclass/click-app.eclass | 162 ++++++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 162 insertions(+)
> > >  create mode 100644 eclass/click-app.eclass
> > > 
> > > 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 <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
> > > +
> > > +readonly _CLICK_COMPLETIONS_BUILD_DIR="${WORKDIR}/${P}_click-shell-completions"
> > > +
> > > +# @FUNCTION: click-app_enable_completions
> > > +# @USAGE: <script...>
> > > +# @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_install_all()
> > > +# if they are already defined (e.g. by distutils_enable_sphinx).  You should 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}" "${@}"
> > > +	(( $# >= 1 )) ||
> > > +		die "${FUNCNAME} takes at least one argument"
> > > +
> > > +	IUSE+=" bash-completion"
> > > +	BDEPEND+=" bash-completion? ( ${RDEPEND} )"
> > > +
> > > +	_CLICK_SCRIPTS=()
> > > +	for script in "${@}"; do
> > > +		_CLICK_SCRIPTS+=( "${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=()
> > > +	for impl in "${PYTHON_COMPAT[@]}"; do
> > > +		use "python_targets_${impl}" &&
> > > +			DISTUTILS_ALL_SUBPHASE_IMPLS+=( "${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: <script>
> > > +# @DESCRIPTION:
> > > +# Build shell completions for a script.
> > > +build_click_completions() {
> > > +	debug-print-function "${FUNCNAME}" "${@}"
> > > +	(( $# == 1 )) ||
> > > +		die "${FUNCNAME} takes exactly one argument"
> > > +
> > > +	local env_var_name out_path script_path t
> > > +
> > > +	script_path="${BUILD_DIR}/install${EPREFIX}/usr/bin/${1}"
> > > +	[[ -f "${script_path}" ]] ||
> > > +		die "${script_path} not found, build_click_completions call wrong"
> > > +
> > > +	# convert to screaming snake case
> > > +	t=${1^^}
> > > +	t=${t//-/_}
> > > +	env_var_name="_${t}_COMPLETE"
> > > +
> > > +	mkdir -p "${_CLICK_COMPLETIONS_BUILD_DIR}" || die
> > > +	for shell in bash fish zsh; do
> > > +		out_path="${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.${shell}"
> > > +
> > > +		echo "${env_var_name}=${shell}_source ${script_path} > ${out_path}" >&2
> > > +		local -x "${env_var_name}"="${shell}_source" || die
> > > +		"${script_path}" > "${out_path}" || die
> > > +	done
> > > +}
> > > +
> > > +# @FUNCTION: install_click_completions
> > > +# @USAGE: <script>
> > > +# @DESCRIPTION:
> > > +# Install generated shell completions for a script.
> > > +install_click_completions() {
> > > +	debug-print-function "${FUNCNAME}" "${@}"
> > > +	(( $# == 1 )) ||
> > > +		die "${FUNCNAME} takes exactly one argument"
> > > +
> > > +	newbashcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.bash" "${1}"
> > > +	newfishcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.fish" "${1}.fish"
> > > +	newzshcomp "${_CLICK_COMPLETIONS_BUILD_DIR}/${1}.zsh" "_${1}"
> > > +}
> > > +
> > > +fi
> > > +
> > > +EXPORT_FUNCTIONS pkg_setup
> > 
> > That sounds like a lot of complexity for something that could be more
> > cleanly achieved by a single function called from python_install()
> > (and detecting that it's been called already by existing completions).
> 
> Ohh, this haven't even crossed my mind, thanks.
> 
> It works (when called before 'distutils-r1_python_install') and makes 
> 'python_compile_all()' subphase unnecessary. Setting BDEPEND is still 
> necessary as build and running environments can be different, if I 
> understand correctly, but 'pkg_setup()' phase can be removed too.

Hmm, I was actually thinking of using the installed version from
the default install but yeah, calling it prior makes even more sense.

> 
> Moreover, it could work without creating temporary files by piping 
> straightly to 'newins -'. However checking $PIPESTATUS might be needed 
> in such case.
> 

Yep.

-- 
Best regards,
Michał Górny


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 512 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-11-24 22:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-23  7:27 [gentoo-guru] [0/2] new eclass: click-app; generate and install shell completions Anna (cybertailor) Vyalkova
2024-11-23  7:27 ` [gentoo-guru] [PATCH 1/2] click-app.eclass: new eclass Anna (cybertailor) Vyalkova
2024-11-24 13:00   ` Takuya Wakazono
2024-11-24 14:30     ` Anna (cybertailor) Vyalkova
2024-11-24 13:21   ` Michał Górny
2024-11-24 14:46     ` Anna (cybertailor) Vyalkova
2024-11-24 15:26       ` Michał Górny
2024-11-23  7:27 ` [gentoo-guru] [PATCH 2/2] dev-util/bump-my-version: add completions support Anna (cybertailor) Vyalkova

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox