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) + 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', diff --git a/virtualenvwrapper/gem.py b/virtualenvwrapper/gem.py index 44fb33e..10ac8c4 100755 --- a/virtualenvwrapper/gem.py +++ b/virtualenvwrapper/gem.py @@ -4,24 +4,72 @@ log = logging.getLogger(__name__) + 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" -export GEM_PATH="" -PATH="$GEM_HOME/bin:$PATH" -export 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+x}" ]; then + 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 +""" 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 [ -e "${VIRTUAL_ENV}/.gem" ]; then + + if [ -n "${_OLD_GEM_HOME+x}" ]; then + GEM_HOME="$_OLD_GEM_HOME" + export GEM_HOME + unset _OLD_GEM_HOME + else + unset GEM_HOME + fi + + if [ -n "${_OLD_GEM_PATH+x}" ]; then + GEM_PATH="$_OLD_GEM_PATH" + export GEM_PATH + unset _OLD_GEM_PATH + 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 """