From b05e164e725f09a60c0b1c926ece26a66892b2b4 Mon Sep 17 00:00:00 2001 From: Paul Prince Date: Sun, 19 Jan 2014 21:31:05 -0500 Subject: [PATCH 1/7] Commit the initial meat of my improvement. Differences in behavior from upstream version: * GEM_HOME will be set to VIRTUAL_ENV instead of VIRTUAL_ENV/lib/gems * As a handy side-effect of this improvement, we will no longer need to add anything to PATH. * Both the values, **and the set/unset** status, of all environmental variables will be preserved and restored properly on deactivating the virtualenv. --- virtualenvwrapper/gem.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/virtualenvwrapper/gem.py b/virtualenvwrapper/gem.py index 44fb33e..3a039f3 100755 --- a/virtualenvwrapper/gem.py +++ b/virtualenvwrapper/gem.py @@ -7,12 +7,16 @@ def post_activate_source(args): return """ #patch to wrap gems inside the virtual env -export _OLD_GEM_HOME="$GEM_HOME" -export _OLD_GEM_PATH="$GEM_PATH" -export GEM_HOME="$VIRTUAL_ENV/lib/gems" + +if [ -n "${GEM_HOME+x}" ]; then + export _OLD_GEM_HOME="$GEM_HOME" +fi +export GEM_HOME=$VIRTUAL_ENV + +if [ -n "${GEM_PATH+1}" ]; then + export _OLD_GEM_PATH="$GEM_PATH" +fi export GEM_PATH="" -PATH="$GEM_HOME/bin:$PATH" -export PATH """ @@ -21,7 +25,21 @@ def post_activate_source(args): def pre_deactivate_source(args): return """ #restore the value before entering the venv -export GEM_HOME="$_OLD_GEM_HOME" -export GEM_PATH="$GEM_PATH" + +if [ -n "${_OLD_GEM_HOME+1}" ]; then + GEM_HOME="$_OLD_GEM_HOME" + export GEM_HOME + unset _OLD_GEM_HOME +else + unset GEM_HOME +fi + +if [ -n "${_OLD_GEM_PATH+1}" ]; then + GEM_PATH="$_OLD_GEM_PATH" + export GEM_PATH + unset _OLD_GEM_PATH +else + unset GEM_PATH +fi """ From 3dfc75443e83035d1b890e6d80f1c9b05c497071 Mon Sep 17 00:00:00 2001 From: Paul Prince Date: Sun, 19 Jan 2014 21:40:31 -0500 Subject: [PATCH 2/7] Correct an incorrect comment. --- virtualenvwrapper/gem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virtualenvwrapper/gem.py b/virtualenvwrapper/gem.py index 3a039f3..e555803 100755 --- a/virtualenvwrapper/gem.py +++ b/virtualenvwrapper/gem.py @@ -24,7 +24,7 @@ def post_activate_source(args): def pre_deactivate_source(args): return """ -#restore the value before entering the venv +#restore the value before exiting the venv if [ -n "${_OLD_GEM_HOME+1}" ]; then GEM_HOME="$_OLD_GEM_HOME" From 903ea584ec4ccd06f2c562d38c094b6e5459bd03 Mon Sep 17 00:00:00 2001 From: Paul Prince Date: Sun, 19 Jan 2014 22:23:58 -0500 Subject: [PATCH 3/7] Add check for .gem inside venv. --- virtualenvwrapper/gem.py | 54 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/virtualenvwrapper/gem.py b/virtualenvwrapper/gem.py index e555803..453e5b2 100755 --- a/virtualenvwrapper/gem.py +++ b/virtualenvwrapper/gem.py @@ -4,42 +4,42 @@ log = logging.getLogger(__name__) + def post_activate_source(args): return """ -#patch to wrap gems inside the virtual env - -if [ -n "${GEM_HOME+x}" ]; then - export _OLD_GEM_HOME="$GEM_HOME" -fi -export GEM_HOME=$VIRTUAL_ENV - -if [ -n "${GEM_PATH+1}" ]; then - export _OLD_GEM_PATH="$GEM_PATH" +if [ -e "${VIRTUAL_ENV}/.gem"; then + if [ -n "${GEM_HOME+x}" ]; then + export _OLD_GEM_HOME="$GEM_HOME" + fi + export GEM_HOME=$VIRTUAL_ENV + + if [ -n "${GEM_PATH+1}" ]; then + export _OLD_GEM_PATH="$GEM_PATH" + fi + export GEM_PATH="" fi -export GEM_PATH="" """ - def pre_deactivate_source(args): return """ -#restore the value before exiting the venv - -if [ -n "${_OLD_GEM_HOME+1}" ]; then - GEM_HOME="$_OLD_GEM_HOME" - export GEM_HOME - unset _OLD_GEM_HOME -else - unset GEM_HOME -fi - -if [ -n "${_OLD_GEM_PATH+1}" ]; then - GEM_PATH="$_OLD_GEM_PATH" - export GEM_PATH - unset _OLD_GEM_PATH -else - unset GEM_PATH +if [ -e "${VIRTUAL_ENV}/.gem"; then + if [ -n "${_OLD_GEM_HOME+1}" ]; then + GEM_HOME="$_OLD_GEM_HOME" + export GEM_HOME + unset _OLD_GEM_HOME + else + unset GEM_HOME + fi + + if [ -n "${_OLD_GEM_PATH+1}" ]; then + GEM_PATH="$_OLD_GEM_PATH" + export GEM_PATH + unset _OLD_GEM_PATH + else + unset GEM_PATH + fi fi """ From 66e41359fffe9697d935919041a3d1c61f5afac3 Mon Sep 17 00:00:00 2001 From: Paul Prince Date: Sun, 19 Jan 2014 22:28:33 -0500 Subject: [PATCH 4/7] Add CONTRIBUTORS file. --- CONTRIBUTORS | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 CONTRIBUTORS diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..7f75ecd --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,8 @@ + +Originally by and Copyright (C) 2012 Rachid Belaid +-------------------------------------------------- + +... with contributions and inspiration from the community, including: + +Paul A. Prince (2014) + From 8784f187056e5fd12c1f2b072c7fdc64399f8d43 Mon Sep 17 00:00:00 2001 From: Paul Prince Date: Sun, 19 Jan 2014 22:31:37 -0500 Subject: [PATCH 5/7] Bump version. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 161dc5c..81cbe79 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name='virtualenvwrapper.gem', - version='0.1', + version='0.2', description='Plugin for virtualenvwrapper to automatically ' 'encapsulate inside the virtual environment' 'any gems installed when the venv is activated', From fc7e9683facff19763b4a8ac5eefaeee640f6467 Mon Sep 17 00:00:00 2001 From: Paul Prince Date: Mon, 20 Jan 2014 02:04:01 -0500 Subject: [PATCH 6/7] Fix bugs. --- virtualenvwrapper/gem.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/virtualenvwrapper/gem.py b/virtualenvwrapper/gem.py index 453e5b2..6bb938d 100755 --- a/virtualenvwrapper/gem.py +++ b/virtualenvwrapper/gem.py @@ -7,13 +7,13 @@ def post_activate_source(args): return """ -if [ -e "${VIRTUAL_ENV}/.gem"; then +if [ -e "${VIRTUAL_ENV}/.gem" ]; then if [ -n "${GEM_HOME+x}" ]; then export _OLD_GEM_HOME="$GEM_HOME" fi export GEM_HOME=$VIRTUAL_ENV - if [ -n "${GEM_PATH+1}" ]; then + if [ -n "${GEM_PATH+x}" ]; then export _OLD_GEM_PATH="$GEM_PATH" fi export GEM_PATH="" @@ -24,8 +24,8 @@ def post_activate_source(args): def pre_deactivate_source(args): return """ -if [ -e "${VIRTUAL_ENV}/.gem"; then - if [ -n "${_OLD_GEM_HOME+1}" ]; then +if [ -e "${VIRTUAL_ENV}/.gem" ]; then + if [ -n "${_OLD_GEM_HOME+x}" ]; then GEM_HOME="$_OLD_GEM_HOME" export GEM_HOME unset _OLD_GEM_HOME @@ -33,7 +33,7 @@ def pre_deactivate_source(args): unset GEM_HOME fi - if [ -n "${_OLD_GEM_PATH+1}" ]; then + if [ -n "${_OLD_GEM_PATH+x}" ]; then GEM_PATH="$_OLD_GEM_PATH" export GEM_PATH unset _OLD_GEM_PATH From afe21e2619c397b6db762c2ea0f1c500f5f63462 Mon Sep 17 00:00:00 2001 From: Paul Prince Date: Fri, 31 Jan 2014 03:55:38 -0500 Subject: [PATCH 7/7] Add Bundler support. --- virtualenvwrapper/gem.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/virtualenvwrapper/gem.py b/virtualenvwrapper/gem.py index 6bb938d..10ac8c4 100755 --- a/virtualenvwrapper/gem.py +++ b/virtualenvwrapper/gem.py @@ -8,6 +8,7 @@ def post_activate_source(args): return """ if [ -e "${VIRTUAL_ENV}/.gem" ]; then + if [ -n "${GEM_HOME+x}" ]; then export _OLD_GEM_HOME="$GEM_HOME" fi @@ -17,6 +18,17 @@ def post_activate_source(args): export _OLD_GEM_PATH="$GEM_PATH" fi export GEM_PATH="" + + if [ -n "${BUNDLE_HOME+x}" ]; then + export _OLD_BUNDLE_HOME="$BUNDLE_HOME" + fi + export BUNDLE_HOME="$GEM_HOME" + + if [ -n "${BUNDLE_BIN+x}" ]; then + export _OLD_BUNDLE_BIN="$BUNDLE_BIN" + fi + export BUNDLE_BIN="${GEM_HOME}/bin" + fi """ @@ -25,6 +37,7 @@ def post_activate_source(args): def pre_deactivate_source(args): return """ if [ -e "${VIRTUAL_ENV}/.gem" ]; then + if [ -n "${_OLD_GEM_HOME+x}" ]; then GEM_HOME="$_OLD_GEM_HOME" export GEM_HOME @@ -40,6 +53,23 @@ def pre_deactivate_source(args): else unset GEM_PATH fi + + if [ -n "${_OLD_BUNDLE_HOME+x}" ]; then + BUNDLE_HOME="$_OLD_BUNDLE_HOME" + export BUNDLE_HOME + unset _OLD_BUNDLE_HOME + else + unset BUNDLE_HOME + fi + + if [ -n "${_OLD_BUNDLE_BIN+x}" ]; then + BUNDLE_BIN="$_OLD_BUNDLE_BIN" + export BUNDLE_BIN + unset _OLD_BUNDLE_BIN + else + unset BUNDLE_BIN + fi + fi """