mirror of
https://github.com/dcarrillo/prezto.git
synced 2024-12-22 15:08:01 +00:00
Support virtualenvwrapper
with / without pyenv
virtualenv-init
or virtualenvwrapper
plugins
The desired logic is: For the `pyenv` plugins `virtualenv-init` and `virtualenvwrapper`: 1. If either plugin is present, activate it 2. If `virtualenvwrapper` plugin is not present, then [fallback to standard `virtualenvwrapper`](https://github.com/sorin-ionescu/prezto/pull/1414#issuecomment-320306421). 3. If `virtualenvwrapper` plugin is present, then [don't fallback to standard `virtualenvwrapper`, regardless of whether `virtualenv-init` is present](https://github.com/sorin-ionescu/prezto/pull/1981#issue-1123766676). Previously, if the `virtualenv` command was present but `pyenv` was missing, then the fallback wouldn't be hit. This bug was introduced by https://github.com/sorin-ionescu/prezto/pull/1981/ which ensured that the `pyenv` `virtualenvwrapper` plugin was activated if present, regardless of the presence of the `virtualenv-init` plugin. As an optimization, the check for the `pyenv` plugins are skipped if `pyenv` itself isn't found. Since we only want to fallback if the `pyenv` `virtualenvwrapper` plugin is missing, but that's buried within the `pyenv` logic and we also need to handle when `pyenv` itself is missing, this switches to using a flag variable. I also renamed the `virtualenv_sources` var to `virtualenvwrapper_sources` as `virtualenv` is distinct from `virtualenvwrapper`, so using one name for a var that is really about the other is confusing. Looking at `git blame`, there's a _lot_ of prior art here around trying to support all the permutations of `pyenv` and various plugins: * https://github.com/sorin-ionescu/prezto/issues/1413 * https://github.com/sorin-ionescu/prezto/pull/1414 * https://github.com/sorin-ionescu/prezto/pull/1433 * https://github.com/sorin-ionescu/prezto/pull/1434 So we need to be extremely careful to continue to support all these permutations. Fix https://github.com/sorin-ionescu/prezto/issues/2022
This commit is contained in:
parent
ca9012c776
commit
e3a9583f33
@ -116,11 +116,11 @@ if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) \
|
|||||||
# look for plugins of interest. Scanning shell '$path' isn't enough as they
|
# look for plugins of interest. Scanning shell '$path' isn't enough as they
|
||||||
# can exist in 'pyenv' synthesized paths (e.g., '~/.pyenv/plugins') instead.
|
# can exist in 'pyenv' synthesized paths (e.g., '~/.pyenv/plugins') instead.
|
||||||
local -a pyenv_plugins
|
local -a pyenv_plugins
|
||||||
|
local pyenv_virtualenvwrapper_plugin_found
|
||||||
if (( $+commands[pyenv] )); then
|
if (( $+commands[pyenv] )); then
|
||||||
pyenv_plugins=(${(@oM)${(f)"$(pyenv commands --no-sh 2> /dev/null)"}:#virtualenv*})
|
pyenv_plugins=(${(@oM)${(f)"$(pyenv commands --no-sh 2> /dev/null)"}:#virtualenv*})
|
||||||
fi
|
|
||||||
|
|
||||||
# Optionally activate 'virtualenv' plugin when available.
|
# Optionally activate 'virtualenv-init' plugin when available.
|
||||||
if (( $pyenv_plugins[(i)virtualenv-init] <= $#pyenv_plugins )); then
|
if (( $pyenv_plugins[(i)virtualenv-init] <= $#pyenv_plugins )); then
|
||||||
eval "$(pyenv virtualenv-init - zsh)"
|
eval "$(pyenv virtualenv-init - zsh)"
|
||||||
fi
|
fi
|
||||||
@ -128,26 +128,30 @@ if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) \
|
|||||||
# Optionally activate 'virtualenvwrapper' plugin when available.
|
# Optionally activate 'virtualenvwrapper' plugin when available.
|
||||||
if (( $pyenv_plugins[(i)virtualenvwrapper(_lazy|)] <= $#pyenv_plugins )); then
|
if (( $pyenv_plugins[(i)virtualenvwrapper(_lazy|)] <= $#pyenv_plugins )); then
|
||||||
pyenv "$pyenv_plugins[(R)virtualenvwrapper(_lazy|)]"
|
pyenv "$pyenv_plugins[(R)virtualenvwrapper(_lazy|)]"
|
||||||
|
pyenv_virtualenvwrapper_plugin_found="true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset pyenv_plugins
|
unset pyenv_plugins
|
||||||
|
fi
|
||||||
|
|
||||||
else
|
if [[ $pyenv_virtualenvwrapper_plugin_found != "true" ]]; then
|
||||||
# Fallback to 'virtualenvwrapper' without 'pyenv' wrapper if 'python' is
|
# Fallback to standard 'virtualenvwrapper' if 'python' is available in '$path'.
|
||||||
# available in '$path'.
|
|
||||||
if (( ! $+VIRTUALENVWRAPPER_PYTHON )) && (( $#commands[(i)python[23]#] )); then
|
if (( ! $+VIRTUALENVWRAPPER_PYTHON )) && (( $#commands[(i)python[23]#] )); then
|
||||||
VIRTUALENVWRAPPER_PYTHON=$commands[(i)python[23]#]
|
VIRTUALENVWRAPPER_PYTHON=$commands[(i)python[23]#]
|
||||||
fi
|
fi
|
||||||
|
|
||||||
virtenv_sources=(
|
virtualenvwrapper_sources=(
|
||||||
${(@Ov)commands[(I)virtualenvwrapper(_lazy|).sh]}
|
${(@Ov)commands[(I)virtualenvwrapper(_lazy|).sh]}
|
||||||
/usr/share/virtualenvwrapper/virtualenvwrapper(_lazy|).sh(OnN)
|
/usr/share/virtualenvwrapper/virtualenvwrapper(_lazy|).sh(OnN)
|
||||||
)
|
)
|
||||||
if (( $#virtenv_sources )); then
|
if (( $#virtualenvwrapper_sources )); then
|
||||||
source "$virtenv_sources[1]"
|
source "$virtualenvwrapper_sources[1]"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset virtenv_sources
|
unset virtualenvwrapper_sources
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset pyenv_virtualenvwrapper_plugin_found
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load conda into the shell session, if requested.
|
# Load conda into the shell session, if requested.
|
||||||
|
Loading…
Reference in New Issue
Block a user