2012-02-01 04:37:51 +00:00
|
|
|
#
|
|
|
|
# Enables local Python package installation.
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
2012-04-12 11:06:37 +00:00
|
|
|
# Sebastian Wiesner <lunaryorn@googlemail.com>
|
2012-02-01 04:37:51 +00:00
|
|
|
#
|
|
|
|
|
2013-08-20 12:21:17 +00:00
|
|
|
# Load manually installed pyenv into the shell session.
|
|
|
|
if [[ -s "$HOME/.pyenv/bin/pyenv" ]]; then
|
|
|
|
path=("$HOME/.pyenv/bin" $path)
|
|
|
|
eval "$(pyenv init -)"
|
2012-09-25 16:57:57 +00:00
|
|
|
|
2013-08-20 12:21:17 +00:00
|
|
|
# Load package manager installed pyenv into the shell session.
|
|
|
|
elif (( $+commands[pyenv] )); then
|
|
|
|
eval "$(pyenv init -)"
|
2012-07-23 19:00:44 +00:00
|
|
|
|
2011-08-27 23:09:06 +00:00
|
|
|
# Prepend PEP 370 per user site packages directory, which defaults to
|
2013-01-28 22:08:56 +00:00
|
|
|
# ~/Library/Python on Mac OS X and ~/.local elsewhere, to PATH.
|
2011-08-27 23:09:06 +00:00
|
|
|
else
|
2013-08-20 12:21:17 +00:00
|
|
|
if [[ "$OSTYPE" == darwin* ]]; then
|
|
|
|
path=($HOME/Library/Python/*/bin(N) $path)
|
|
|
|
else
|
|
|
|
# This is subject to change.
|
|
|
|
path=($HOME/.local/bin $path)
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Return if requirements are not found.
|
|
|
|
if (( ! $+commands[python] && ! $+commands[pyenv] )); then
|
|
|
|
return 1
|
2011-08-27 23:09:06 +00:00
|
|
|
fi
|
|
|
|
|
2013-12-20 09:09:45 +00:00
|
|
|
local venv_script=virtualenvwrapper
|
|
|
|
if zstyle -T ':prezto:module:python' lazy_venv; then
|
|
|
|
venv_script+=_lazy
|
|
|
|
fi
|
|
|
|
|
2012-04-12 11:06:37 +00:00
|
|
|
# Load virtualenvwrapper into the shell session.
|
2013-12-20 09:09:45 +00:00
|
|
|
if (( $+commands[$venv_script.sh] )); then
|
2012-09-03 14:53:19 +00:00
|
|
|
# Set the directory where virtual environments are stored.
|
2013-08-20 12:21:17 +00:00
|
|
|
export WORKON_HOME="$HOME/.virtualenvs"
|
2012-09-03 14:53:19 +00:00
|
|
|
|
2012-09-03 14:34:41 +00:00
|
|
|
# Disable the virtualenv prompt.
|
|
|
|
VIRTUAL_ENV_DISABLE_PROMPT=1
|
2012-09-03 14:53:19 +00:00
|
|
|
|
2013-12-20 09:09:45 +00:00
|
|
|
source "$commands[$venv_script.sh]"
|
2012-04-12 11:06:37 +00:00
|
|
|
fi
|
|
|
|
|
2013-12-20 09:09:45 +00:00
|
|
|
function autoenv {
|
|
|
|
#Don't run in shell scripts etc.
|
|
|
|
if [[ $ZSH_SUBSHELL -ne 0 ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
#Don't run if currently in virtual env not set by autoenv
|
|
|
|
if (( ($+VIRTUAL_ENV) && !($+AUTOENV) )); then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
local name=""
|
|
|
|
if [[ -f .venv ]]; then
|
|
|
|
#.venv file in current dir gets highest priority
|
|
|
|
name=$(<.venv)
|
|
|
|
elif is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
|
|
|
|
local gitroot="$(git rev-parse --show-toplevel 2> /dev/null)"
|
|
|
|
if [ -f "$gitroot/.venv" ]; then
|
|
|
|
#If there is a .venv file in gitroot
|
|
|
|
name=$(<$gitroot/.venv)
|
|
|
|
else
|
|
|
|
#Else use the name of the folder as venv name
|
|
|
|
name=$gitroot:t
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
local venv_name="$VIRTUAL_ENV:t"
|
|
|
|
if [[ $name != $venv_name ]]; then
|
|
|
|
if [[ -z $name ]]; then
|
|
|
|
deactivate && unset AUTOENV
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -d "$WORKON_HOME/$name" ]]; then
|
|
|
|
workon $name && export AUTOENV=1
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if zstyle -T ':prezto:module:python' autoenv; then
|
|
|
|
add-zsh-hook chpwd autoenv
|
|
|
|
fi
|
2012-08-15 12:00:08 +00:00
|
|
|
#
|
|
|
|
# Aliases
|
|
|
|
#
|
|
|
|
|
|
|
|
alias py='python'
|
2012-09-03 01:14:32 +00:00
|
|
|
|