Ian Bicking: the old part of his blog

Re: Working env comment 000

Your activate script is also kind of tricky (i.e., it looks like "activating" twice really means deactivate). If I may make a suggestion to rename it "toggle-wenv" or something to make that clearer.

Also, if PYTHONPATH is unset when it is run, the new PYTHONPATH will have a trailing ':' which may result in including the current working directory in the PYTHONPATH which may not be the best idea. It also may be harmless, but I don't think it hurts to be careful, especially if other modifying scripts acticipate a well-formed PYTHONPATH variable.

In addition, I might suggest using more unique names for your saved PYTHONPATH and PATH variables (this is a common trick and one probably doesn't want to risk a name clash). Here's a patch for working-env.py which includes all my suggestions (it's also a little friendlier to those WORKING_ENV paths which contain spaces:

--- working-env.py      2006-04-20 23:21:49.000000000 -0700
+++ working-env.py.new  2006-04-21 10:09:50.000000000 -0700
@@ -203,22 +203,22 @@
 script_dir = __WORKING__/bin/
 """
 
-files_to_write['bin/activate'] = """\
-# This file must be used with "source bin/activate"
+files_to_write['bin/toggle-wenv'] = """\
+# This file must be used with "source bin/toggle-wenv"
 # you cannot run it directly
-export WORKING_ENV=%(working_env)s
-if [ -n "$_OLD_WORKING_PATH" ] ; then
-    PATH="$_OLD_WORKING_PATH"
+export WORKING_ENV='%(working_env)s'
+if [ -n "$_WORKING_ENV_OLD_PATH" ] ; then
+    PATH="$_WORKING_ENV_OLD_PATH"
 else
-    _OLD_WORKING_PATH="$PATH"
+    _WORKING_ENV_OLD_PATH="$PATH"
 fi
 export PATH=$WORKING_ENV/bin:$PATH
-if [ -n "$_OLD_PYTHONPATH" ] ; then
-    PYTHONPATH="$_OLD_PYTHONPATH"
+if [ -n "$_WORKING_ENV_OLD_PYTHONPATH" ] ; then
+    PYTHONPATH="$_WORKING_ENV_OLD_PYTHONPATH"
 else
-    _OLD_PYTHONPATH="$PYTHONPATH"
+    _WORKING_ENV_OLD_PYTHONPATH="$PYTHONPATH"
 fi
-export PYTHONPATH=$WORKING_ENV/lib/python%(python_version)s:$PYTHONPATH
+export PYTHONPATH="$WORKING_ENV/lib/python%(python_version)s${PYTHONPATH:+:}$PYTHONPATH"
 """
 
 def make_working_environment(

I hope this helps a little.

Comment on Working env comment 000
by mbogosian

Comments:

Oops....

I forgot to also change this line:

export PATH=$WORKING_ENV/bin:$PATH

To this (note the quotes):

export PATH="$WORKING_ENV/bin:$PATH"
# mbogosian