From a0f89bc1f8875093ce80cb3846a24451e6401209 Mon Sep 17 00:00:00 2001 From: Luke Culbertson Date: Thu, 25 Sep 2014 17:23:53 -0700 Subject: [PATCH 1/5] Added better support for pyenv, virtualenvwrapper, and autoenv working in concert with one another. Features added: - Added a pyenv-virtualenv plugin which creates virtual environments using the current pyenv python version - `cd` into a directory that has a virtual environment already created and autoenv will automatically activate that environment - Current virtual environment is displayed in command prompt --- .../available/pyenv-virtualenv.plugin.bash | 58 +++++++++++++++++++ plugins/available/pyenv.plugin.bash | 5 +- themes/bobby/bobby.theme.bash | 2 +- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 plugins/available/pyenv-virtualenv.plugin.bash diff --git a/plugins/available/pyenv-virtualenv.plugin.bash b/plugins/available/pyenv-virtualenv.plugin.bash new file mode 100644 index 00000000..1f45dcb2 --- /dev/null +++ b/plugins/available/pyenv-virtualenv.plugin.bash @@ -0,0 +1,58 @@ +# make sure virtualenvwrapper is enabled if available + +cite about-plugin +about-plugin 'pyenv-virtualenvwrapper helper functions' + +export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true" + +# Activate autoenv +source /usr/local/opt/autoenv/activate.sh + +function mkenv { + about 'create a new virtualenv for this directory' + group 'pyenv-virtualenv' + + eval "touch .env" + eval "echo \"#!/bin/bash\" >> .env" + eval "echo \"eval \"wovenv\"\" >> .env" + cwd=`basename \`pwd\`` + mkvirtualenv --distribute $cwd +} + +function mkvbranch { + about 'create a new virtualenv for the current branch' + group 'pyenv-virtualenv' + + mkvirtualenv --distribute "$(basename `pwd`)@$SCM_BRANCH" +} + +function wovbranch { + about 'sets workon branch' + group 'pyenv-virtualenv' + + workon "$(basename `pwd`)@$SCM_BRANCH" +} + +function wovenv { + about 'works on the virtualenv for this directory' + group 'virtualenv' + + workon "$(basename `pwd`)" +} + +function rmenv { + about 'removes virtualenv for this directory' + group 'virtualenv' + + eval "deactivate" + rmvirtualenv "$(basename `pwd`)" + eval "rm .env" +} + +function rmenvbranch { + about 'removes virtualenv for this directory' + group 'virtualenv' + + eval "deactivate" + rmvirtualenv "$(basename `pwd`)@$SCM_BRANCH" +} \ No newline at end of file diff --git a/plugins/available/pyenv.plugin.bash b/plugins/available/pyenv.plugin.bash index 7ed2d3cd..a9034ee7 100644 --- a/plugins/available/pyenv.plugin.bash +++ b/plugins/available/pyenv.plugin.bash @@ -1,8 +1,9 @@ cite about-plugin about-plugin 'load pyenv, if you are using it' -export PYENV_ROOT="$HOME/.pyenv" -export PATH="$PYENV_ROOT/bin:$PATH" +export PYENV_PATH=`which pyenv` +export PATH="$PYENV_PATH:$PATH" + [[ `which pyenv` ]] && eval "$(pyenv init -)" #Load pyenv virtualenv if the virtualenv plugin is installed. diff --git a/themes/bobby/bobby.theme.bash b/themes/bobby/bobby.theme.bash index 308b412b..ccb71edd 100644 --- a/themes/bobby/bobby.theme.bash +++ b/themes/bobby/bobby.theme.bash @@ -14,7 +14,7 @@ RVM_THEME_PROMPT_SUFFIX="|" function prompt_command() { #PS1="${bold_cyan}$(scm_char)${green}$(scm_prompt_info)${purple}$(ruby_version_prompt) ${yellow}\h ${reset_color}in ${green}\w ${reset_color}\n${green}→${reset_color} " - PS1="\n${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} " + PS1="\n${yellow}$(virtualenv_prompt)$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} " } PROMPT_COMMAND=prompt_command; From 7240a657065bb28af5bb82c5c33ab45ac25d2aa0 Mon Sep 17 00:00:00 2001 From: Luke Culbertson Date: Thu, 25 Sep 2014 22:20:30 -0700 Subject: [PATCH 2/5] Changed pvenv functions to avoid name conflicts --- plugins/available/pyenv-virtualenv.plugin.bash | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/available/pyenv-virtualenv.plugin.bash b/plugins/available/pyenv-virtualenv.plugin.bash index 1f45dcb2..78a1a550 100644 --- a/plugins/available/pyenv-virtualenv.plugin.bash +++ b/plugins/available/pyenv-virtualenv.plugin.bash @@ -8,39 +8,39 @@ export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true" # Activate autoenv source /usr/local/opt/autoenv/activate.sh -function mkenv { +function mkpvenv { about 'create a new virtualenv for this directory' group 'pyenv-virtualenv' eval "touch .env" eval "echo \"#!/bin/bash\" >> .env" - eval "echo \"eval \"wovenv\"\" >> .env" + eval "echo \"eval \"wopvenv\"\" >> .env" cwd=`basename \`pwd\`` mkvirtualenv --distribute $cwd } -function mkvbranch { +function mkpvbranch { about 'create a new virtualenv for the current branch' group 'pyenv-virtualenv' mkvirtualenv --distribute "$(basename `pwd`)@$SCM_BRANCH" } -function wovbranch { +function wopvbranch { about 'sets workon branch' group 'pyenv-virtualenv' workon "$(basename `pwd`)@$SCM_BRANCH" } -function wovenv { +function wopvenv { about 'works on the virtualenv for this directory' group 'virtualenv' workon "$(basename `pwd`)" } -function rmenv { +function rmpvenv { about 'removes virtualenv for this directory' group 'virtualenv' @@ -49,7 +49,7 @@ function rmenv { eval "rm .env" } -function rmenvbranch { +function rmpvenvbranch { about 'removes virtualenv for this directory' group 'virtualenv' From 228ac4ceec932a8d1d698a7d60d34ae50b5f51e5 Mon Sep 17 00:00:00 2001 From: Luke Culbertson Date: Thu, 2 Oct 2014 00:16:39 -0700 Subject: [PATCH 3/5] Run `pyenv virtualenvwrapper` and remove virtualenv-init cmd --- plugins/available/pyenv-virtualenv.plugin.bash | 2 ++ plugins/available/pyenv.plugin.bash | 5 ----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/available/pyenv-virtualenv.plugin.bash b/plugins/available/pyenv-virtualenv.plugin.bash index 78a1a550..ca262b51 100644 --- a/plugins/available/pyenv-virtualenv.plugin.bash +++ b/plugins/available/pyenv-virtualenv.plugin.bash @@ -5,6 +5,8 @@ about-plugin 'pyenv-virtualenvwrapper helper functions' export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true" +[[ `which pyenv` ]] && eval "$(pyenv virtualenv)" + # Activate autoenv source /usr/local/opt/autoenv/activate.sh diff --git a/plugins/available/pyenv.plugin.bash b/plugins/available/pyenv.plugin.bash index a9034ee7..dd712f87 100644 --- a/plugins/available/pyenv.plugin.bash +++ b/plugins/available/pyenv.plugin.bash @@ -6,10 +6,5 @@ export PATH="$PYENV_PATH:$PATH" [[ `which pyenv` ]] && eval "$(pyenv init -)" -#Load pyenv virtualenv if the virtualenv plugin is installed. -if pyenv virtualenv-init - &> /dev/null; then - eval "$(pyenv virtualenv-init -)" -fi - # Load the auto-completion script if pyenv was loaded. [[ -e $PYENV_ROOT/completions/pyenv.bash ]] && source $PYENV_ROOT/completions/pyenv.bash From d42ac438b11d426a1e7fc875f17973938d3eb880 Mon Sep 17 00:00:00 2001 From: Luke Culbertson Date: Thu, 9 Oct 2014 17:53:54 -0700 Subject: [PATCH 4/5] Added pyenv-init to allow pyenv virtualenvwrapper to init properly --- plugins/available/pyenv-virtualenv.plugin.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/available/pyenv-virtualenv.plugin.bash b/plugins/available/pyenv-virtualenv.plugin.bash index ca262b51..096a2a60 100644 --- a/plugins/available/pyenv-virtualenv.plugin.bash +++ b/plugins/available/pyenv-virtualenv.plugin.bash @@ -5,7 +5,8 @@ about-plugin 'pyenv-virtualenvwrapper helper functions' export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true" -[[ `which pyenv` ]] && eval "$(pyenv virtualenv)" +[[ `which pyenv` ]] && eval "$(pyenv init -)" +[[ `which pyenv-virtualenvwrapper` ]] && eval "$(pyenv virtualenvwrapper)" # Activate autoenv source /usr/local/opt/autoenv/activate.sh From 3a943e58130d6ef34891e1d54690180cb147c681 Mon Sep 17 00:00:00 2001 From: luke Date: Mon, 27 Oct 2014 10:31:19 -0700 Subject: [PATCH 5/5] Skip workon if not in root directory --- plugins/available/pyenv-virtualenv.plugin.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/available/pyenv-virtualenv.plugin.bash b/plugins/available/pyenv-virtualenv.plugin.bash index 096a2a60..65ccd41e 100644 --- a/plugins/available/pyenv-virtualenv.plugin.bash +++ b/plugins/available/pyenv-virtualenv.plugin.bash @@ -15,10 +15,10 @@ function mkpvenv { about 'create a new virtualenv for this directory' group 'pyenv-virtualenv' + cwd=`basename \`pwd\`` eval "touch .env" eval "echo \"#!/bin/bash\" >> .env" - eval "echo \"eval \"wopvenv\"\" >> .env" - cwd=`basename \`pwd\`` + eval "echo \"if [ \\\`basename \\\$(pwd)\\\` == \\\"$cwd\\\" ]; then \"eval \"wopvenv\"\"; fi\" >> .env" mkvirtualenv --distribute $cwd }