From c1c5bc160d2963f6dd2216da0528c24e7425fd5f Mon Sep 17 00:00:00 2001 From: odrling Date: Fri, 5 Apr 2024 23:38:50 +0200 Subject: [PATCH] dev-python/typer: fix shell completions typer outputs the completion for python -m, installing the typer wrapper doesn't seem to be easy so just remove it from the generated completions and install that --- dev-python/typer/typer-0.12.1.ebuild | 43 +++++++++++++++++++--------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/dev-python/typer/typer-0.12.1.ebuild b/dev-python/typer/typer-0.12.1.ebuild index cec0932..76b5955 100644 --- a/dev-python/typer/typer-0.12.1.ebuild +++ b/dev-python/typer/typer-0.12.1.ebuild @@ -39,8 +39,6 @@ RDEPEND=" ') " -COMPLETIONSDIR="${WORKDIR}/comp" - distutils_enable_tests pytest src_test() { @@ -50,24 +48,43 @@ src_test() { distutils-r1_src_test "${@}" } -typer_gen_comp() { - python -m typer --show-completion bash > "${COMPLETIONSDIR}/${PN}" - python -m typer --show-completion zsh > "${COMPLETIONSDIR}/_${PN}" - python -m typer --show-completion fish > "${COMPLETIONSDIR}/${PN}.fish" -} - src_compile() { distutils-r1_src_compile "${@}" - mkdir "${COMPLETIONSDIR}" + local shell + for shell in bash zsh fish; do + typer_gencomp ${shell} + done +} - _TYPER_COMPLETE_TEST_DISABLE_SHELL_DETECTION=1 typer_gen_comp +typer_get_comp() { + local COMPLETIONSDIR="${WORKDIR}/comp" + local shell="$1" + + case "${shell}" in + bash) echo "${COMPLETIONSDIR}/${PN}" ;; + zsh) echo "${COMPLETIONSDIR}/_${PN}" ;; + fish) echo "${COMPLETIONSDIR}/${PN}.fish" ;; + *) die "unknown shell: ${shell}" ;; + esac +} + +typer_gencomp() { + local COMPLETIONSDIR="${WORKDIR}/comp" + mkdir "${COMPLETIONSDIR}" 2> /dev/null + local shell="$1" + + compfile="$(typer_get_comp "${@}")" + + _TYPER_COMPLETE_TEST_DISABLE_SHELL_DETECTION=1 python -m typer --show-completion "${shell}" | + sed 's/python -m //g ; s/_PYTHON _M //g' > "${compfile}" || + die "failed to generate ${shell} completion" } src_install() { distutils-r1_src_install "${@}" - dobashcomp "${COMPLETIONSDIR}/${PN}" - dozshcomp "${COMPLETIONSDIR}/_${PN}" - dofishcomp "${COMPLETIONSDIR}/${PN}.fish" + dobashcomp "$(typer_get_comp bash)" + dozshcomp "$(typer_get_comp zsh)" + dofishcomp "$(typer_get_comp fish)" }