mirror of
https://github.com/dcarrillo/prezto.git
synced 2025-07-01 02:19:25 +00:00
[python] Improve and document virtualenvwrapper
initialization flow
Changes: * Simplify zstyle name `skip-virtualenvwrapper-init` to `initialize` avoiding double negation in name * Always perform `eval (pyenv virtualenv-init -)` at initialization * Prefer `virtualenvwrapper_lazy` over `virtualenvwrapper` when available * Honor `VIRTUALENVWRAPPER_VIRTUALENV` if it is defined. * Document about `VIRTUALENVWRAPPER_PYTHON` and `VIRTUALENVWRAPPER_VIRTUALENV` (this would be particularly important in macOS after recent homebrew update) * Add additional documentation for `initialize` in _README.md_ and _zpreztorc_ * Add aliases `py2`, `py3` as shortcut for `python2`, `python3` respectively
This commit is contained in:
committed by
Indrajit Raychaudhuri
parent
7e7124e84a
commit
19435b16ea
@ -82,26 +82,32 @@ if zstyle -t ':prezto:module:python:virtualenv' auto-switch 'yes'; then
|
||||
add-zsh-hook chpwd _python-workon-cwd
|
||||
fi
|
||||
|
||||
# Load virtualenvwrapper into the shell session, unless requested not to
|
||||
if zstyle -T ':prezto:module:python' skip-virtualenvwrapper-init; then
|
||||
# Load virtualenvwrapper into the shell session, if pre-requisites are met
|
||||
# and unless explicitly requested not to
|
||||
if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) && \
|
||||
zstyle -T ':prezto:module:python:virtualenv' initialize ; then
|
||||
# Set the directory where virtual environments are stored.
|
||||
export WORKON_HOME="${WORKON_HOME:-$HOME/.virtualenvs}"
|
||||
|
||||
# Disable the virtualenv prompt.
|
||||
VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||
|
||||
if (( $+commands[pyenv-virtualenvwrapper] )); then
|
||||
pyenv virtualenvwrapper
|
||||
elif (( $+commands[pyenv-virtualenv-init] )); then
|
||||
eval "$(pyenv virtualenv-init -)"
|
||||
elif (( $+commands[virtualenvwrapper_lazy.sh] )); then
|
||||
source "$commands[virtualenvwrapper_lazy.sh]"
|
||||
elif (( $+commands[virtualenvwrapper.sh] )); then
|
||||
source "$commands[virtualenvwrapper.sh]"
|
||||
elif [[ -f /usr/share/virtualenvwrapper/virtualenvwrapper_lazy.sh ]]; then
|
||||
source /usr/share/virtualenvwrapper/virtualenvwrapper_lazy.sh
|
||||
elif [[ -f /usr/share/virtualenvwrapper/virtualenvwrapper.sh ]]; then
|
||||
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh
|
||||
if (( $+commands[pyenv] )); then
|
||||
if (( $+commands[pyenv-virtualenv-init] )); then
|
||||
eval "$(pyenv virtualenv-init -)"
|
||||
fi
|
||||
if (( $#commands[(i)pyenv-virtualenvwrapper(_lazy|)] )); then
|
||||
pyenv "${${(@O)commands[(I)pyenv-virtualenvwrapper(_lazy|)]}[1]#pyenv-}"
|
||||
fi
|
||||
else
|
||||
# Try 'virtualenvwrapper' without 'pyenv' wrapper in '$path' and other
|
||||
# known locations on a Debian based system.
|
||||
virtenv_sources=(
|
||||
${(@Ov)commands[(I)virtualenvwrapper(_lazy|).sh]}
|
||||
/usr/share/virtualenvwrapper/virtualenvwrapper(_lazy|).sh(OnN)
|
||||
)
|
||||
source "${virtenv_sources[1]}"
|
||||
unset virtenv_sources
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -109,7 +115,7 @@ fi
|
||||
if (( $#commands[(i)pip(|[23])] )); then
|
||||
cache_file="${0:h}/cache.zsh"
|
||||
|
||||
# Detect and use first one available among 'pip', 'pip2', 'pip3' variants
|
||||
# Detect and use one available from among 'pip', 'pip2', 'pip3' variants
|
||||
pip_command="$commands[(i)pip(|[23])]"
|
||||
|
||||
if [[ "$pip_command" -nt "$cache_file" || ! -s "$cache_file" ]]; then
|
||||
@ -119,8 +125,7 @@ if (( $#commands[(i)pip(|[23])] )); then
|
||||
fi
|
||||
|
||||
source "$cache_file"
|
||||
unset cache_file
|
||||
unset pip_command
|
||||
unset cache_file pip_command
|
||||
fi
|
||||
|
||||
#
|
||||
@ -128,3 +133,5 @@ fi
|
||||
#
|
||||
|
||||
alias py='python'
|
||||
alias py2='python2'
|
||||
alias py3='python3'
|
||||
|
Reference in New Issue
Block a user