mirror of
https://github.com/dcarrillo/prezto.git
synced 2024-12-22 18:38:00 +00:00
Ask pyenv whether pip exists if installed (#1848)
Pyenv will install shims for commands that exist in any interpreter, even if it is not the current one. This means that a command may technically exist, but when executed will tell the user to try a different interpreter. The original check for pip in the Python module can fail for this reason, in particular on Ubuntu 20.04. This change checks with pyenv whether pip really exists in the current interpreter to work around this problem and fixes a bug in pip command detection.
This commit is contained in:
parent
20a78c04e5
commit
2d3763380c
@ -147,18 +147,25 @@ if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) && \
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Load PIP completion.
|
# Load PIP completion.
|
||||||
if (( $#commands[(i)pip(|[23])] )); then
|
# Detect and use one available from among 'pip', 'pip2', 'pip3' variants
|
||||||
cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/pip-cache.zsh"
|
if [[ -n "$PYENV_ROOT" ]]; then
|
||||||
|
for pip in pip{,2,3}; do
|
||||||
# Detect and use one available from among 'pip', 'pip2', 'pip3' variants
|
pip_command="$(pyenv which "$pip" 2>/dev/null)"
|
||||||
|
[[ -n "$pip_command" ]] && break
|
||||||
|
done
|
||||||
|
unset pip
|
||||||
|
else
|
||||||
pip_command="$commands[(i)pip(|[23])]"
|
pip_command="$commands[(i)pip(|[23])]"
|
||||||
|
fi
|
||||||
|
if [[ -n "$pip_command" ]]; then
|
||||||
|
cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/pip-cache.zsh"
|
||||||
|
|
||||||
if [[ "$pip_command" -nt "$cache_file" \
|
if [[ "$pip_command" -nt "$cache_file" \
|
||||||
|| "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \
|
|| "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \
|
||||||
|| ! -s "$cache_file" ]]; then
|
|| ! -s "$cache_file" ]]; then
|
||||||
mkdir -p "$cache_file:h"
|
mkdir -p "$cache_file:h"
|
||||||
# pip is slow; cache its output. And also support 'pip2', 'pip3' variants
|
# pip is slow; cache its output. And also support 'pip2', 'pip3' variants
|
||||||
$pip_command completion --zsh \
|
"$pip_command" completion --zsh \
|
||||||
| sed -e "s/\(compctl -K [-_[:alnum:]]* pip\).*/\1{,2,3}{,.{0..9}}/" \
|
| sed -e "s/\(compctl -K [-_[:alnum:]]* pip\).*/\1{,2,3}{,.{0..9}}/" \
|
||||||
>! "$cache_file" \
|
>! "$cache_file" \
|
||||||
2> /dev/null
|
2> /dev/null
|
||||||
@ -166,8 +173,9 @@ if (( $#commands[(i)pip(|[23])] )); then
|
|||||||
|
|
||||||
source "$cache_file"
|
source "$cache_file"
|
||||||
|
|
||||||
unset cache_file pip_command
|
unset cache_file
|
||||||
fi
|
fi
|
||||||
|
unset pip_command
|
||||||
|
|
||||||
# Load conda into the shell session, if requested
|
# Load conda into the shell session, if requested
|
||||||
zstyle -T ':prezto:module:python' conda-init
|
zstyle -T ':prezto:module:python' conda-init
|
||||||
|
Loading…
Reference in New Issue
Block a user