From dba399fe6a41615d0a59899f7ac6dfdd26a42731 Mon Sep 17 00:00:00 2001 From: Wu Zhenyu Date: Sat, 22 Jul 2023 15:31:12 +0800 Subject: [PATCH] Fix #12166 - tests expected results indendation was off - add bugfix news entry --- news/12166.bugfix.rst | 1 + src/pip/_internal/commands/completion.py | 15 ++++++++++++--- tests/functional/test_completion.py | 15 ++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 news/12166.bugfix.rst diff --git a/news/12166.bugfix.rst b/news/12166.bugfix.rst new file mode 100644 index 000000000..491597c7f --- /dev/null +++ b/news/12166.bugfix.rst @@ -0,0 +1 @@ +Fix completion script for zsh diff --git a/src/pip/_internal/commands/completion.py b/src/pip/_internal/commands/completion.py index 30233fc7a..9e89e2798 100644 --- a/src/pip/_internal/commands/completion.py +++ b/src/pip/_internal/commands/completion.py @@ -23,9 +23,18 @@ COMPLETION_SCRIPTS = { """, "zsh": """ #compdef -P pip[0-9.]# - compadd $( COMP_WORDS="$words[*]" \\ - COMP_CWORD=$((CURRENT-1)) \\ - PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null ) + __pip() {{ + compadd $( COMP_WORDS="$words[*]" \\ + COMP_CWORD=$((CURRENT-1)) \\ + PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null ) + }} + if [[ $zsh_eval_context[-1] == loadautofunc ]]; then + # autoload from fpath, call function directly + __pip "$@" + else + # eval/source/. command, register function for later + compdef __pip -P 'pip[0-9.]#' + fi """, "fish": """ function __fish_complete_pip diff --git a/tests/functional/test_completion.py b/tests/functional/test_completion.py index 2e3f31729..2aa861aac 100644 --- a/tests/functional/test_completion.py +++ b/tests/functional/test_completion.py @@ -44,9 +44,18 @@ complete -fa "(__fish_complete_pip)" -c pip""", "zsh", """\ #compdef -P pip[0-9.]# -compadd $( COMP_WORDS="$words[*]" \\ - COMP_CWORD=$((CURRENT-1)) \\ - PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )""", +__pip() { + compadd $( COMP_WORDS="$words[*]" \\ + COMP_CWORD=$((CURRENT-1)) \\ + PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null ) +} +if [[ $zsh_eval_context[-1] == loadautofunc ]]; then + # autoload from fpath, call function directly + __pip "$@" +else + # eval/source/. command, register function for later + compdef __pip -P 'pip[0-9.]#' +fi""", ), ( "powershell",