Skip to content

Commit 17eec7b

Browse files
committed
add user-provided tips to the docs
1 parent 61a2f90 commit 17eec7b

File tree

3 files changed

+171
-6
lines changed

3 files changed

+171
-6
lines changed

docsource/developers.rst

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,27 @@
22
For Developers
33
##############
44

5-
If you would like to contribute, these instructions should help you get started. Patches, bug reports, and feature requests are all welcome through the `BitBucket site <http://bitbucket.org/dhellmann/virtualenvwrapper/>`_. Contributions in the form of patches or pull requests are easier to integrate and will receive priority attention.
5+
If you would like to contribute, these instructions should help you
6+
get started. Patches, bug reports, and feature requests are all
7+
welcome through the `BitBucket site
8+
<http://bitbucket.org/dhellmann/virtualenvwrapper/>`_. Contributions
9+
in the form of patches or pull requests are easier to integrate and
10+
will receive priority attention.
611

712
Building Documentation
813
======================
914

10-
The documentation for virtualenvwrapper is written in reStructuredText and converted to HTML using Sphinx. The build itself is driven by Paver. You will need the following packages in order to build the docs:
15+
The documentation for virtualenvwrapper is written in reStructuredText
16+
and converted to HTML using Sphinx. The build itself is driven by
17+
Paver. You will need the following packages in order to build the
18+
docs:
1119

1220
- Sphinx
1321
- Paver
1422
- sphinxcontrib.paverutils
1523

16-
Once all of them are installed into a virtualenv using easy_install, run ``paver html`` to generate the HTML version of the documentation::
24+
Once all of them are installed into a virtualenv using easy_install,
25+
run ``paver html`` to generate the HTML version of the documentation::
1726

1827
$ paver html
1928
---> pavement.html
@@ -47,12 +56,16 @@ Once all of them are installed into a virtualenv using easy_install, run ``paver
4756
rmtree virtualenvwrapper/docs () {}
4857
move docs/html virtualenvwrapper/docs
4958

50-
The output version of the documentation ends up in ``./virtualenvwrapper/docs`` inside your sandbox.
59+
The output version of the documentation ends up in
60+
``./virtualenvwrapper/docs`` inside your sandbox.
5161

5262
Running Tests
5363
=============
5464

55-
The test suite for virtualenvwrapper uses `shunit2 <http://shunit2.googlecode.com/>`_. To run the tests under both bash and zsh, use ``paver test``. To add new tests, modify the ``tests/test.sh`` script with new test functions.
65+
The test suite for virtualenvwrapper uses `shunit2
66+
<http://shunit2.googlecode.com/>`_. To run the tests under both bash
67+
and zsh, use ``paver test``. To add new tests, modify the
68+
``tests/test.sh`` script with new test functions.
5669

5770
::
5871

@@ -127,4 +140,4 @@ The test suite for virtualenvwrapper uses `shunit2 <http://shunit2.googlecode.co
127140

128141
Ran 12 tests.
129142

130-
OK
143+
OK

docsource/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Details
5353

5454
command_ref
5555
hooks
56+
tips
5657
history
5758
developers
5859

docsource/tips.rst

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
=================
2+
Tips and Tricks
3+
=================
4+
5+
This is a list of user-contributed tips for making virtualenv and
6+
virtualenvwrapper even more useful. If you have tip to share, drop me
7+
an email or post a comment on `this blog post
8+
<http://blog.doughellmann.com/2010/01/virtualenvwrapper-tips-and-tricks.html>`__
9+
and I'll add it here.
10+
11+
zsh Prompt
12+
==========
13+
14+
From `Nat <http://www.blogger.com/profile/16779944428406910187>`_:
15+
16+
Using zsh, I added some bits to ``$WORKON_HOME/post(de)activate`` to show
17+
the active virtualenv on the right side of my screen instead.
18+
19+
in ``postactivate``::
20+
21+
PS1="$_OLD_VIRTUAL_PS1"
22+
_OLD_RPROMPT="$RPROMPT"
23+
RPROMPT="%{${fg_bold[white]}%}(env: %{${fg[green]}%}`basename \"$VIRTUAL_ENV\"`%{${fg_bold[white]}%})%{${reset_color}%} $RPROMPT"
24+
25+
and in ``postdeactivate``::
26+
27+
RPROMPT="$_OLD_RPROMPT"
28+
29+
Adjust colors according to your own personal tastes or environment.
30+
31+
Updating cached ``$PATH`` entries
32+
=================================
33+
34+
From `Nat <http://www.blogger.com/profile/16779944428406910187>`_:
35+
36+
I also added the command 'rehash' to ``$WORKON_HOME/postactivate`` and
37+
``$WORKON_HOME/postdeactivate`` as I was having some problems with zsh
38+
not picking up the new paths immediately.
39+
40+
Tying to pip's virtualenv support
41+
=================================
42+
43+
Via http://becomingguru.com/:
44+
45+
Add this to your shell login script to make pip use the same directory
46+
for virtualenvs as virtualenvwrapper::
47+
48+
export PIP_VIRTUALENV_BASE=$WORKON_HOME
49+
50+
and Via Nat:
51+
52+
in addition to what becomingguru said, this line is key::
53+
54+
export PIP_RESPECT_VIRTUALENV=true
55+
56+
That makes pip detect an active virtualenv and install to it, without
57+
having to pass it the -E parameter.
58+
59+
Creating Project Work Directories
60+
=================================
61+
62+
Via `James <http://www.blogger.com/profile/02618224969192901883>`_:
63+
64+
In the ``postmkvirtualenv`` script I have the following to create a
65+
directory based on the project name, add that directory to the python
66+
path and then cd into it::
67+
68+
proj_name=$(echo $VIRTUAL_ENV|awk -F'/' '{print $NF}')
69+
mkdir $HOME/projects/$proj_name
70+
add2virtualenv $HOME/projects/$proj_name
71+
cd $HOME/projects/$proj_name
72+
73+
74+
In the ``postactivate`` script I have it set to automatically change
75+
to the project directory when I use the workon command::
76+
77+
proj_name=$(echo $VIRTUAL_ENV|awk -F'/' '{print $NF}')
78+
cd ~/projects/$proj_name
79+
80+
Automatically Run workon When Entering a Directory
81+
==================================================
82+
83+
`Justin Lily posted
84+
<http://justinlilly.com/blog/2009/mar/28/virtualenv-wrapper-helper/>`__
85+
about about some code he added to his shell environment to look at the
86+
directory each time he runs ``cd``. If it finds a ``.venv`` file, it
87+
activates the environment named within. On leaving that directory,
88+
the current virtualenv is automatically deactivated.
89+
90+
`Harry Marr <http://www.blogger.com/profile/17141199633387157732>`__
91+
wrote a similar function that works with `git repositories
92+
<http://hmarr.com/2010/jan/19/making-virtualenv-play-nice-with-git/>`__.
93+
94+
Installing Common Tools Automatically in New Environments
95+
=========================================================
96+
97+
Via `rizumu <http://rizumu.myopenid.com/>`__:
98+
99+
I have this postmkvirtualenv to install the get a basic setup.
100+
101+
::
102+
103+
$ cat postmkvirtualenv
104+
#!/usr/bin/env bash
105+
curl -O http://python-distribute.org/distribute_setup.p... />python distribute_setup.py
106+
rm distribute_setup.py
107+
easy_install pip==dev
108+
pip install Mercurial
109+
110+
Then I have a pip requirement file with my dev tools.
111+
112+
::
113+
114+
$ cat developer_requirements.txt
115+
ipdb
116+
ipython
117+
pastescript
118+
nose
119+
http://douglatornell.ca/software/python/Nosy-1.0.tar.gz
120+
coverage
121+
sphinx
122+
grin
123+
pyflakes
124+
pep8
125+
126+
Then each project has it's own pip requirement file for things like
127+
PIL, psycopg2, django-apps, numpy, etc.
128+
129+
Changing the Default Behavior of ``cd``
130+
=======================================
131+
132+
Via `mae <http://www.blogger.com/profile/10879711379090472478>`__:
133+
134+
This is supposed to be executed after workon, that is as a
135+
``postactivate`` hook. It basically overrides ``cd`` to know about the
136+
VENV so instead of doing ``cd`` to go to ``~`` you will go to the venv
137+
root, IMO very handy and I can't live without it anymore. if you pass
138+
it a proper path then it will do the right thing.
139+
140+
::
141+
142+
cd () {
143+
if (( $# == 0 ))
144+
then
145+
builtin cd $VIRTUAL_ENV
146+
else
147+
builtin cd "$@"
148+
fi
149+
}
150+
151+
cd

0 commit comments

Comments
 (0)