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
This commit is contained in:
odrling 2024-04-05 23:38:50 +02:00
parent d7c2de9c39
commit c1c5bc160d
No known key found for this signature in database
GPG key ID: EC907F69A27A90C5

View file

@ -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)"
}