Skip to content

Commit f663a81

Browse files
committed
add docs; fix space issues
--HG-- extra : convert_revision : svn%3A98f53aa3-d424-0410-b225-a548b0275c4d/Projects/virtualenvwrapper/trunk%401774
1 parent 4938a5d commit f663a81

File tree

2 files changed

+69
-8
lines changed

2 files changed

+69
-8
lines changed

README

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,58 @@ Sometimes it is desirable to share installed packages that are not in the system
2828
3. Run: ``add2virtualenv``.
2929
4. A usage message and list of current "extra" paths is printed.
3030

31+
==================
32+
Activation Scripts
33+
==================
34+
35+
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.
36+
37+
Both scripts are bash shell scripts and need to be saved in ``$VIRTUAL_ENV/bin/``.
38+
39+
postactivate
40+
============
41+
42+
The ``postactivate`` script is run after the new environment is enabled. ``$VIRTUAL_ENV`` refers to the new environment at the time the script runs.
43+
44+
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.
45+
46+
::
47+
48+
pymotw_root=/Users/dhellmann/Documents/PyMOTW
49+
cd $pymotw_root
50+
PATH=$pymotw_root/bin:$PATH
51+
52+
predeactivate
53+
=============
54+
55+
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.
56+
57+
===============
58+
Path Management
59+
===============
60+
61+
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.
62+
3163
==========
3264
References
3365
==========
3466

35-
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>`_.
67+
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>`_.
68+
69+
=======
70+
Updates
71+
=======
72+
73+
1.5
74+
75+
- Fix some issues with spaces in directory or env names. They still don't really work with virtualenv, though.
76+
- Added documentation for the postactivate and predeactivate scripts.
77+
78+
1.4
79+
80+
- Includes a new .pth management function based on work contributed by James Bennett and Jannis Leidel.
81+
82+
1.3.x
83+
84+
- Includes a fix for a nasty bug in rmvirtualenv identified by John Shimek.
85+

virtualenvwrapper_bashrc

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,33 @@ function verify_workon_environment () {
5252

5353
# Verify that the active environment exists
5454
function verify_active_environment () {
55-
if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d ${VIRTUAL_ENV} ]
55+
if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d "${VIRTUAL_ENV}" ]
5656
then
5757
echo "ERROR: no virtualenv active, or active virtualenv is missing"
5858
return 1
5959
fi
6060
return 0
6161
}
6262

63+
# Print the last argument given to us.
64+
# There has to be a smarter way to do this!
65+
function _lastarg () {
66+
local a
67+
for a in "$@"
68+
do
69+
echo $a
70+
done | tail -1
71+
}
72+
6373
# Create a new environment, in the WORKON_HOME.
6474
#
6575
# Usage: mkvirtualenv [options] ENVNAME
6676
# (where the options are passed directly to virtualenv)
6777
#
6878
function mkvirtualenv () {
6979
verify_workon_home
70-
(cd "$WORKON_HOME"; virtualenv $*)
71-
workon "${@:-1}"
80+
(cd "$WORKON_HOME"; virtualenv "$@")
81+
workon $(_lastarg "$@")
7282
}
7383

7484
# Remove an environment, in the WORKON_HOME.
@@ -161,15 +171,16 @@ function add2virtualenv () {
161171

162172
verify_active_environment || return 1
163173

164-
site_packages=$VIRTUAL_ENV/lib/python`python -c "import sys; print sys.version[:3]"`/site-packages
174+
pyvers="`python -c 'import sys; print sys.version[:3]'`"
175+
site_packages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
165176

166177
if [ ! -d "${site_packages}" ]
167178
then
168179
echo "ERROR: currently-active virtualenv does not appear to have a site-packages directory"
169180
return 1
170181
fi
171182

172-
path_file=$site_packages/virtualenv_path_extensions.pth
183+
path_file="$site_packages/virtualenv_path_extensions.pth"
173184

174185
if [ "$*" = "" ]
175186
then
@@ -183,10 +194,10 @@ function add2virtualenv () {
183194
return 1
184195
fi
185196

186-
touch $path_file
197+
touch "$path_file"
187198
for pydir in "$@"
188199
do
189-
echo $pydir >> "$path_file"
200+
echo "$pydir" >> "$path_file"
190201
done
191202
return 0
192203
}

0 commit comments

Comments
 (0)