Doug Hellmann avatar Doug Hellmann committed fb56732

add docs; fix space issues

Comments (0)

Files changed (2)

 3. Run: ``add2virtualenv``.
 4. A usage message and list of current "extra" paths is printed.
 
+==================
+Activation Scripts
+==================
+
+virtualenvwrapper adds two separate hook scripts you can use to change your settings when moving between environments.  They are *sourced* by ``workon`` at the appropriate trigger time, allowing them to modify your shell environment.
+
+Both scripts are bash shell scripts and need to be saved in ``$VIRTUAL_ENV/bin/``.
+
+postactivate
+============
+
+The ``postactivate`` script is run after the new environment is enabled.  ``$VIRTUAL_ENV`` refers to the new environment at the time the script runs.
+
+This example script for the PyMOTW environment changes the current working directory and the PATH variable to refer to the source tree containing the PyMOTW source.
+
+::
+
+	pymotw_root=/Users/dhellmann/Documents/PyMOTW
+	cd $pymotw_root
+	PATH=$pymotw_root/bin:$PATH
+
+predeactivate
+=============
+
+The ``predeactivate`` script is run before the current environment is deactivated, and can be used to disable or clear settings in your environment.  ``$VIRTUAL_ENV`` refers to the old environment at the time the script runs.
+
+===============
+Path Management
+===============
+
+The function ``add2virtualenv`` adds the specified directories to the Python path for the active virtualenv. The directory names passed as argument are added to a path file named ``virtualenv_path_extensions.pth`` inside the virtualenv's site-packages directory. If this file does not exist, it will be created first.
+
 ==========
 References
 ==========
 
-For more details, refer to the column I wrote for the May 2008 issue of Python Magazine: `virtualenvwrapper | And Now For Something Completely Different <http://www.doughellmann.com/articles/CompletelyDifferent-2008-05-virtualenvwrapper/index.html>`_.
+For more details, refer to the column I wrote for the May 2008 issue of Python Magazine: `virtualenvwrapper | And Now For Something Completely Different <http://www.doughellmann.com/articles/CompletelyDifferent-2008-05-virtualenvwrapper/index.html>`_.
+
+=======
+Updates
+=======
+
+1.5
+
+  - Fix some issues with spaces in directory or env names.  They still don't really work with virtualenv, though.
+  - Added documentation for the postactivate and predeactivate scripts.
+
+1.4
+
+  - Includes a new .pth management function based on work contributed by James Bennett and Jannis Leidel.
+
+1.3.x
+
+  - Includes a fix for a nasty bug in rmvirtualenv identified by John Shimek.
+

virtualenvwrapper_bashrc

 
 # Verify that the active environment exists
 function verify_active_environment () {
-    if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d ${VIRTUAL_ENV} ]
+    if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d "${VIRTUAL_ENV}" ]
     then
         echo "ERROR: no virtualenv active, or active virtualenv is missing"
         return 1
     return 0
 }
 
+# Print the last argument given to us.
+# There has to be a smarter way to do this!
+function _lastarg () {
+    local a
+    for a in "$@"
+    do
+        echo $a
+    done | tail -1
+}
+
 # Create a new environment, in the WORKON_HOME.
 #
 # Usage: mkvirtualenv [options] ENVNAME
 #
 function mkvirtualenv () {
     verify_workon_home
-    (cd "$WORKON_HOME"; virtualenv $*)
-    workon "${@:-1}"
+    (cd "$WORKON_HOME"; virtualenv "$@") 
+    workon $(_lastarg "$@")
 }
 
 # Remove an environment, in the WORKON_HOME.
 
     verify_active_environment || return 1
     
-    site_packages=$VIRTUAL_ENV/lib/python`python -c "import sys; print sys.version[:3]"`/site-packages
+    pyvers="`python -c 'import sys; print sys.version[:3]'`"
+    site_packages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
     
     if [ ! -d "${site_packages}" ]
     then
         return 1
     fi
     
-    path_file=$site_packages/virtualenv_path_extensions.pth
+    path_file="$site_packages/virtualenv_path_extensions.pth"
 
     if [ "$*" = "" ]
     then
         return 1
     fi
 
-    touch $path_file
+    touch "$path_file"
     for pydir in "$@"
     do
-        echo $pydir >> "$path_file"
+        echo "$pydir" >> "$path_file"
     done
     return 0
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.