dhellmann / virtualenvwrapper (http://doughellmann.com/projects/virtualenvwrapper/)

Extensions to Ian Bicking's virtualenv tool. Downloads are available from http://www.doughellmann.com/projects/virtualenv... or you can install with easy_install.

Changed (Δ7.8 KB):

raw changeset »

docs/source/command_ref.rst (2 lines added, 0 lines removed)

docs/source/extensions.rst (13 lines added, 1 lines removed)

docs/source/index.rst (118 lines added, 53 lines removed)

docs/source/install.rst (72 lines added, 0 lines removed)

docs/source/plugins.rst (66 lines added, 22 lines removed)

Up to file-list docs/source/command_ref.rst:

1
1
.. Quick reference documentation for virtualenvwrapper command line functions
2
2
    Originally contributed Thursday, May 28, 2009 by Steve Steiner (ssteinerX@gmail.com)
3
3
4
.. _command:
5
4
6
#################
5
7
Command Reference
6
8
#################

Up to file-list docs/source/extensions.rst:

@@ -16,7 +16,7 @@ templates to virtualenvwrapper.
16
16
bitbucket
17
17
---------
18
18
19
The bitbucket_ extension creates a project working directory and
19
The bitbucket_ project template creates a working directory and
20
20
automatically clones the repository from BitBucket.  Requires
21
21
project_.
22
22
@@ -24,6 +24,18 @@ project_.
24
24
25
25
.. _bitbucket: http://www.doughellmann.com/projects/virtualenvwrapper.bitbucket/
26
26
27
emacs-desktop
28
=============
29
30
Emacs desktop-mode_ lets you save the state of emacs (open buffers,
31
kill rings, buffer positions, etc.) between sessions.  It can also be
32
used as a project file similar to other IDEs.  The emacs-desktop_
33
plugin adds a trigger to save the current desktop file and load a new
34
one when activating a new virtualenv using ``workon``.
35
36
.. _desktop-mode: http://www.emacswiki.org/emacs/DeskTop
37
38
.. _emacs-desktop: http://www.doughellmann.com/projects/virtualenvwrapper-emacs-desktop/
27
39
28
40
user_scripts
29
41
============

Up to file-list docs/source/index.rst:

@@ -29,77 +29,141 @@ 6. Plugin system for more creating shara
29
29
   :ref:`plugins`).
30
30
31
31
============
32
Installation
32
Introduction
33
33
============
34
34
35
WORKON_HOME
36
===========
35
The best way to explain the features virtualenvwrapper gives you is to
36
show it in use.
37
37
38
The variable ``WORKON_HOME`` tells virtualenvwrapper where to place
39
your virtual environments.  The default is ``$HOME/.virtualenvs``.
40
This directory must be created before using any virtualenvwrapper
41
commands.
38
First, some initialization steps.  Most of this only needs to be done
39
one time.  You will want to add the command to ``source
40
/usr/local/bin/virtualenvwrapper.sh`` to your shell startup file,
41
changing the path to virtualenvwrapper.sh depending on where it was
42
installed by pip.
42
43
43
Shell Startup File
44
==================
44
::
45
45
46
Add two lines to your shell startup file (``.bashrc``, ``.profile``,
47
etc.) to set the location where the virtual environments should live
48
and the location of the script installed with this package::
46
  $ pip install virtualenvwrapper
47
  ...
48
  $ export WORKON_HOME=~/Envs
49
  $ mkdir -p $WORKON_HOME
50
  $ source /usr/local/bin/virtualenvwrapper.sh
51
  $ mkvirtualenv env1
52
  Installing
53
  distribute..........................................
54
  ....................................................
55
  ....................................................
56
  ...............................done.
57
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/predeactivate
58
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/postdeactivate
59
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/preactivate
60
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/postactivate  New python executable in env1/bin/python
61
  (env1)$ ls $WORKON_HOME
62
  env1 hook.log
49
63
50
    export WORKON_HOME=$HOME/.virtualenvs
51
    source /usr/local/bin/virtualenvwrapper.sh
64
Now we can install some software into the environment.
52
65
53
After editing it, reload the startup file (e.g., run: ``source
54
~/.bashrc``).
66
::
55
67
56
Python Interpreter and $PATH
57
============================
68
  (env1)$ pip install django
69
  Downloading/unpacking django
70
    Downloading Django-1.1.1.tar.gz (5.6Mb): 5.6Mb downloaded
71
    Running setup.py egg_info for package django
72
  Installing collected packages: django
73
    Running setup.py install for django
74
      changing mode of build/scripts-2.6/django-admin.py from 644 to 755
75
      changing mode of /Users/dhellmann/Envs/env1/bin/django-admin.py to 755
76
  Successfully installed django
58
77
59
During startup, ``virtualenvwrapper.sh`` finds the first ``python`` on
60
the ``$PATH`` and remembers it to use later.  This eliminates any
61
conflict as the ``$PATH`` changes, enabling interpreters inside
62
virtual environments where virtualenvwrapper is not installed.
63
Because of this behavior, it is important for the ``$PATH`` to be set
64
**before** sourcing ``virtualenvwrapper.sh``.  For example::
78
We can see the new package with ``lssitepackages``::
65
79
66
    export PATH=/usr/local/bin:$PATH
67
    source /usr/local/bin/virtualenvwrapper.sh
80
  (env1)$ lssitepackages
81
  Django-1.1.1-py2.6.egg-info     easy-install.pth
82
  distribute-0.6.10-py2.6.egg     pip-0.6.3-py2.6.egg
83
  django                          setuptools.pth
68
84
69
To override the ``$PATH`` search, set the variable
70
``VIRTUALENVWRAPPER_PYTHON`` to the full path of the interpreter to
71
use (also **before** sourcing ``virtualenvwrapper.sh``).  For
72
example::
85
Of course we are not limited to a single virtualenv::
73
86
74
    export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
75
    source /usr/local/bin/virtualenvwrapper.sh
87
  (env1)$ ls $WORKON_HOME
88
  env1            hook.log
89
  (env1)$ mkvirtualenv env2
90
  Installing distribute...............................
91
  ....................................................
92
  ....................................................
93
  ........... ...............................done.
94
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/predeactivate
95
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/postdeactivate
96
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/preactivate
97
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/postactivate  New python executable in env2/bin/python
98
  (env2)$ ls $WORKON_HOME
99
  env1            env2            hook.log
76
100
77
Quick-Start
78
===========
101
Switch between environments with ``workon``::
79
102
80
1. Run: ``workon``
81
2. A list of environments, empty, is printed.
82
3. Run: ``mkvirtualenv temp``
83
4. A new environment, ``temp`` is created and activated.
84
5. Run: ``workon``
85
6. This time, the ``temp`` environment is included.
103
  (env2)$ workon env1
104
  (env1)$ echo $VIRTUAL_ENV
105
  /Users/dhellmann/Envs/env1
106
  (env1)$ 
86
107
87
Temporary Files
88
===============
108
The ``workon`` command also includes tab completion for the
109
environment names, and invokes customization scripts as an environment
110
is activated or deactivated (see :ref:`scripts`).
89
111
90
virtualenvwrapper creates temporary files in ``$TMPDIR``.  If the
91
variable is not set, it uses ``/tmp``.  To change the location of
92
temporary files just for virtualenvwrapper, set
93
``VIRTUALENVWRAPPER_TMPDIR``.
112
::
94
113
95
Upgrading from 1.x
96
==================
114
  (env1)$ echo 'cd $VIRTUAL_ENV' >> $WORKON_HOME/postactivate
115
  (env1)$ workon env2
116
  (env2)$ pwd
117
  /Users/dhellmann/Envs/env2
97
118
98
The shell script containing the wrapper functions has been renamed in
99
the 2.x series to reflect the fact that shells other than bash are
100
supported.  In your startup file, change ``source
101
/usr/local/bin/virtualenvwrapper_bashrc`` to ``source
102
/usr/local/bin/virtualenvwrapper.sh``.
119
:ref:`scripts-postmkvirtualenv` is run when a new environment is
120
created, letting you automatically install commonly-used tools.
121
122
::
123
124
  (env2)$ echo 'pip install sphinx' >> $WORKON_HOME/postmkvirtualenv
125
  (env3)$ mkvirtualenv env3
126
  New python executable in env3/bin/python
127
  Installing distribute...............................
128
  ....................................................
129
  ....................................................
130
  ........... ...............................done.
131
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/predeactivate
132
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/postdeactivate
133
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/preactivate
134
  virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/postactivate
135
  Downloading/unpacking sphinx
136
    Downloading Sphinx-0.6.5.tar.gz (972Kb): 972Kb downloaded
137
    Running setup.py egg_info for package sphinx
138
      no previously-included directories found matching 'doc/_build'
139
  Downloading/unpacking Pygments>=0.8 (from sphinx)
140
    Downloading Pygments-1.3.1.tar.gz (1.1Mb): 1.1Mb downloaded
141
    Running setup.py egg_info for package Pygments
142
  Downloading/unpacking Jinja2>=2.1 (from sphinx)
143
    Downloading Jinja2-2.4.tar.gz (688Kb): 688Kb downloaded
144
    Running setup.py egg_info for package Jinja2
145
      warning: no previously-included files matching '*' found under directory 'docs/_build/doctrees'
146
  Downloading/unpacking docutils>=0.4 (from sphinx)
147
    Downloading docutils-0.6.tar.gz (1.4Mb): 1.4Mb downloaded
148
    Running setup.py egg_info for package docutils
149
  Installing collected packages: docutils, Jinja2, Pygments, sphinx
150
    Running setup.py install for docutils
151
    Running setup.py install for Jinja2
152
    Running setup.py install for Pygments
153
    Running setup.py install for sphinx
154
      no previously-included directories found matching 'doc/_build'
155
      Installing sphinx-build script to /Users/dhellmann/Envs/env3/bin
156
      Installing sphinx-quickstart script to /Users/dhellmann/Envs/env3/bin
157
      Installing sphinx-autogen script to /Users/dhellmann/Envs/env3/bin
158
  Successfully installed docutils Jinja2 Pygments sphinx  (env3)$ 
159
  (venv3)$ which sphinx-build
160
  /Users/dhellmann/Envs/env3/bin/sphinx-build
161
162
Through a combination of the existing functions defined by the core
163
package (see :ref:`command`), third-party plugins (see
164
:ref:`plugins`), and user-defined scripts (see :ref:`scripts`)
165
virtualenvwrapper gives you a wide variety of opportunities to
166
automate repetitive operations.
103
167
104
168
=======
105
169
Details
@@ -108,6 +172,7 @@ Details
108
172
.. toctree::
109
173
   :maxdepth: 2
110
174
175
   install
111
176
   command_ref
112
177
   hooks
113
178
   tips

Up to file-list docs/source/install.rst:

1
============
2
Installation
3
============
4
5
WORKON_HOME
6
===========
7
8
The variable ``WORKON_HOME`` tells virtualenvwrapper where to place
9
your virtual environments.  The default is ``$HOME/.virtualenvs``.
10
This directory must be created before using any virtualenvwrapper
11
commands.
12
13
Shell Startup File
14
==================
15
16
Add two lines to your shell startup file (``.bashrc``, ``.profile``,
17
etc.) to set the location where the virtual environments should live
18
and the location of the script installed with this package::
19
20
    export WORKON_HOME=$HOME/.virtualenvs
21
    source /usr/local/bin/virtualenvwrapper.sh
22
23
After editing it, reload the startup file (e.g., run: ``source
24
~/.bashrc``).
25
26
Python Interpreter and $PATH
27
============================
28
29
During startup, ``virtualenvwrapper.sh`` finds the first ``python`` on
30
the ``$PATH`` and remembers it to use later.  This eliminates any
31
conflict as the ``$PATH`` changes, enabling interpreters inside
32
virtual environments where virtualenvwrapper is not installed.
33
Because of this behavior, it is important for the ``$PATH`` to be set
34
**before** sourcing ``virtualenvwrapper.sh``.  For example::
35
36
    export PATH=/usr/local/bin:$PATH
37
    source /usr/local/bin/virtualenvwrapper.sh
38
39
To override the ``$PATH`` search, set the variable
40
``VIRTUALENVWRAPPER_PYTHON`` to the full path of the interpreter to
41
use (also **before** sourcing ``virtualenvwrapper.sh``).  For
42
example::
43
44
    export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
45
    source /usr/local/bin/virtualenvwrapper.sh
46
47
Quick-Start
48
===========
49
50
1. Run: ``workon``
51
2. A list of environments, empty, is printed.
52
3. Run: ``mkvirtualenv temp``
53
4. A new environment, ``temp`` is created and activated.
54
5. Run: ``workon``
55
6. This time, the ``temp`` environment is included.
56
57
Temporary Files
58
===============
59
60
virtualenvwrapper creates temporary files in ``$TMPDIR``.  If the
61
variable is not set, it uses ``/tmp``.  To change the location of
62
temporary files just for virtualenvwrapper, set
63
``VIRTUALENVWRAPPER_TMPDIR``.
64
65
Upgrading from 1.x
66
==================
67
68
The shell script containing the wrapper functions has been renamed in
69
the 2.x series to reflect the fact that shells other than bash are
70
supported.  In your startup file, change ``source
71
/usr/local/bin/virtualenvwrapper_bashrc`` to ``source
72
/usr/local/bin/virtualenvwrapper.sh``.

Up to file-list docs/source/plugins.rst:

4
4
Extending Virtualenvwrapper
5
5
===========================
6
6
7
Customizing one's development environment is a practice adopted from
8
other tool-based jobs in which long experience leads to home-grown and
9
unique solutions to persistent annoyances.  Carpenters build jigs,
10
software developers write shell scripts.  virtualenvwrapper continues
11
the tradition of encouraging a craftsman to modify his tools to work
12
the way he wants, rather than the other way around.
7
Long experience with home-grown solutions for customizing a
8
development environment has proven how valuable it can be to have the
9
ability to automate common tasks and eliminate persistent annoyances.
10
Carpenters build jigs, software developers write shell scripts.
11
virtualenvwrapper continues the tradition of encouraging a craftsman
12
to modify their tools to work the way they want, rather than the other
13
way around.
13
14
14
15
Use the hooks provided to eliminate repetitive manual operations and
15
streamline your development workflow.  For example, the pre_activate
16
and post_activate hooks can trigger an IDE to load a project file to
17
reload files from the last editing session, manage time-tracking
18
records, or start and stop development versions of an application
19
server.  The initialize hook can be used to add entirely new commands
20
and hooks to virtualenvwrapper.  And the pre_mkvirtualenv and
21
post_mkvirtualenv hooks give you an opportunity to install basic
22
requirements into each new development environment, initialize a
23
source code control repository, or otherwise set up a new project.
16
streamline your development workflow.  For example, set up the
17
:ref:`plugins-pre_activate` and :ref:`plugins-post_activate` hooks to
18
trigger an IDE to load a project file to reload files from the last
19
editing session, manage time-tracking records, or start and stop
20
development versions of an application server.  Use the
21
:ref:`plugins-initialize` hook to add entirely new commands and hooks
22
to virtualenvwrapper.  And the :ref:`plugins-pre_mkvirtualenv` and
23
:ref:`plugins-post_mkvirtualenv` hooks give you an opportunity to
24
install basic requirements into each new development environment,
25
initialize a source code control repository, or otherwise set up a new
26
project.
24
27
25
28
There are two ways to attach your code so that virtualenvwrapper will
26
29
run it: End-users can use shell scripts or other programs for personal
@@ -222,15 +225,20 @@ application, use the ``-m`` option to th
222
225
223
226
  $ python -m virtualenvwrapper.hook_loader -h
224
227
  Usage: virtualenvwrapper.hook_loader [options] <hook> [<arguments>]
225
228
  
226
229
  Manage hooks for virtualenvwrapper
227
230
  
228
231
  Options:
229
    -h, --help     show this help message and exit
230
    -s, --source   Print the shell commands to be run in the current shell
231
    -v, --verbose  Show more information on the console
232
    -q, --quiet    Show less information on the console
233
232
    -h, --help            show this help message and exit
233
    -s, --source          Print the shell commands to be run in the current
234
                          shell
235
    -l, --list            Print a list of the plugins available for the given
236
                          hook
237
    -v, --verbose         Show more information on the console
238
    -q, --quiet           Show less information on the console
239
    -n NAMES, --name=NAMES
240
                          Only run the hook from the named plugin
241
  
234
242
To run the extensions for the initialize hook::
235
243
236
244
  $ python -m virtualenvwrapper.hook_loader -v initialize
@@ -239,6 +247,15 @@ To get the shell commands for the initia
239
247
240
248
  $ python -m virtualenvwrapper.hook_loader --source initialize
241
249
250
In practice, rather than invoking the hook loader directly it is more
251
convenient to use the shell function, ``virtualenvwrapper_run_hook``
252
to run the hooks in both modes.::
253
254
  $ virtualenvwrapper_run_hook initialize
255
256
All of the arguments given to shell function are passed directly to
257
the hook loader.
258
242
259
Logging
243
260
-------
244
261
@@ -365,5 +382,32 @@ The ``virtualenvwrapper.post_rmvirtualen
365
382
an environment is deleted.  The name of the environment being deleted
366
383
is passed as the first argument.
367
384
385
Adding New Extension Points
386
===========================
387
388
Plugins that define new operations can also define new extension
389
points.  No setup needs to be done to allow the hook loader to find
390
the extensions; documenting the names and adding calls to
391
``virtualenvwrapper_run_hook`` is sufficient to cause them to be
392
invoked.  
393
394
The hook loader assumes all extension point names start with
395
``virtualenvwrapper.`` and new plugins will want to use their own
396
namespace qualifier to append to that.  For example, the project_
397
extension defines new events around creating project directories (pre
398
and post).  These are called
399
``virtualenvwrapper.project.pre_mkproject`` and
400
``virtualenvwrapper.project.post_mkproject``.  These are invoked
401
with::
402
403
  virtualenvwrapper_run_hook project.pre_mkproject $project_name
404
405
and::
406
407
  virtualenvwrapper_run_hook project.post_mkproject
408
409
respectively.
368
410
369
411
.. _Distribute: http://packages.python.org/distribute/
412
413
.. _project: http://www.doughellmann.com/projects/virtualenvwrapper.project/