Skip to content

Commit 21bf8b9

Browse files
committed
Reworded the documentation around user scripts vs plugin creation, to make it more clear which one you need. Also added a simple example of user scripts.
1 parent 9c70267 commit 21bf8b9

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

docs/source/hooks.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
virtualenvwrapper adds several hook points you can use to change your
66
settings, shell environment, or other configuration values when
77
creating, deleting, or moving between environments. These hooks are
8-
exposed in two ways:
8+
exposed in two ways. :ref:`scripts` allows a user to perform generic actions
9+
for every virtualenv in your environment, including customization of
10+
virtualenv creation. :ref:`plugins` makes it possible to share common
11+
behaviors between systems and developers.
912

1013
.. toctree::
1114
:maxdepth: 1

docs/source/plugins.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ virtualenvwrapper continues the tradition of encouraging a craftsman
1212
to modify their tools to work the way they want, rather than the other
1313
way around.
1414

15+
There are two ways to attach your code so that virtualenvwrapper will
16+
run it: End-users can use shell scripts or other programs for personal
17+
customization, e.g. automatically performing an action on every new
18+
virtualenv (see :ref:`scripts`). Extensions can also be
19+
implemented in Python by using Distribute_ *entry points*, making it
20+
possible to share common behaviors between systems and developers.
21+
1522
Use the hooks provided to eliminate repetitive manual operations and
1623
streamline your development workflow. For example, set up the
1724
:ref:`plugins-pre_activate` and :ref:`plugins-post_activate` hooks to
@@ -25,12 +32,6 @@ install basic requirements into each new development environment,
2532
initialize a source code control repository, or otherwise set up a new
2633
project.
2734

28-
There are two ways to attach your code so that virtualenvwrapper will
29-
run it: End-users can use shell scripts or other programs for personal
30-
customization (see :ref:`scripts`). Extensions can also be
31-
implemented in Python by using Distribute_ *entry points*, making it
32-
possible to share common behaviors between systems and developers.
33-
3435
Defining an Extension
3536
=====================
3637

docs/source/scripts.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,29 @@ the appropriate trigger time.
1010

1111
The global scripts applied to all environments should be placed in the
1212
directory named by :ref:`VIRTUALENVWRAPPER_HOOK_DIR
13-
<variable-VIRTUALENVWRAPPER_HOOK_DIR>`. The local scripts should be
13+
<variable-VIRTUALENVWRAPPER_HOOK_DIR>`, which by default will be equal
14+
to :ref:`WORKON_HOME <variable-WORKON_HOME>`. The local scripts should be
1415
placed in the ``bin`` directory of the virtualenv.
1516

17+
Example Usage
18+
===============
19+
20+
As a Django developer, you likely want DJANGO_SETTINGS_MODULE to be set, and
21+
if you work on multiple projects, you want it to be specific to the project
22+
you are currently working on. Wouldn't it be nice if it was set based on the
23+
active virtualenv? You can achieve this with :ref:`scripts` as follows.
24+
25+
If your :ref:`WORKON_HOME <variable-WORKON_HOME>` is set to ~/.virtualenvs:
26+
27+
vim ~/.virtualenvs/premkvirtualenv
28+
29+
Edit the file so it contains the following (for a default Django setup):
30+
31+
# Automatically set django settings for the virtualenv
32+
echo "export DJANGO_SETTINGS_MODULE=$1.settings" >> "$1/bin/activate"
33+
34+
Create a new virtualenv, and you should see DJANGO_SETTINGS_MODULE in your env!
35+
1636
.. _scripts-get_env_details:
1737

1838
get_env_details

0 commit comments

Comments
 (0)