Skip to content

Commit a37242f

Browse files
committed
more doc cleanup
1 parent e54cf3f commit a37242f

File tree

2 files changed

+53
-34
lines changed

2 files changed

+53
-34
lines changed

docs/source/extensions.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Existing Extensions
33
=====================
44

5-
make_hooks
5+
.. _extensions-user_scripts:
66

77
user_scripts
8+
============
9+

docs/source/plugins.rst

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ Defining an Extension
1616
.. note::
1717

1818
Virtualenvwrapper is delivered with a plugin for creating and
19-
running the user customization scripts. The examples below are
20-
taken from the implementation of that plugin.
19+
running the user customization scripts
20+
(:ref:`extensions-user_scripts`). The examples below are taken from
21+
the implementation of that plugin.
2122

2223
Code Organization
2324
-----------------
@@ -40,8 +41,10 @@ And placing the following code in the ``__init__.py``::
4041

4142
__import__('pkg_resources').declare_namespace(__name__)
4243

43-
This isn't required, so if you would prefer to use a different
44-
namespace that will work, too.
44+
.. note::
45+
46+
Extensions can be loaded from any package, so using the
47+
``virtualenvwrapper`` namespace is not required.
4548

4649
Extension API
4750
-------------
@@ -54,23 +57,24 @@ imported from elsewhere using standard Python code organization
5457
techniques.
5558

5659
The API is the same for every extension point. Each uses a Python
57-
function that takes a single argument, a list of string arguments
58-
passed to the hook loader on the command line. The contents of the
59-
argument list are defined for each extension point below (see
60-
:ref:`plugins-extension-points`).
60+
function that takes a single argument, a list of strings passed to the
61+
hook loader on the command line.
6162

6263
::
6364

6465
def function_name(args):
6566
# args is a list of strings passed to the hook loader
6667

68+
The contents of the argument list are defined for each extension point
69+
below (see :ref:`plugins-extension-points`).
70+
6771
Extension Invocation
6872
--------------------
6973

7074
Plugins can attach to each hook in two different ways. The default is
71-
to have an extension function run and do some work directly. For
72-
example, the ``initialize()`` hook for the user scripts plugin makes
73-
sure the scripts exist every time ``virtualenvwrapper.sh`` is loaded.
75+
to have a function run and do some work directly. For example, the
76+
``initialize()`` function for the user scripts plugin creates default
77+
user scripts when ``virtualenvwrapper.sh`` is loaded.
7478

7579
::
7680

@@ -88,10 +92,10 @@ There are cases where the extension needs to update the user's
8892
environment (e.g., changing the current working directory or setting
8993
environment variables). Modifications to the user environment must be
9094
made within the user's current shell, and cannot be run in a separate
91-
process. Extensions can define hook functions to return the text of
92-
the shell statements to be executed. These *source* hooks are run
93-
after the regular hooks with the same name, and should not do any work
94-
of their own.
95+
process. To have code run in the user's shell process, extensions can
96+
define hook functions to return the text of the shell statements to be
97+
executed. These *source* hooks are run after the regular hooks with
98+
the same name, and should not do any work of their own.
9599

96100
The ``initialize_source()`` hook for the user scripts plugin looks for
97101
a global initialize script and causes it to be run in the current
@@ -112,11 +116,11 @@ shell process.
112116
Because the extension is modifying the user's working shell, care
113117
must be taken not to corrupt the environment by overwriting
114118
existing variable values unexpectedly. Avoid creating temporary
115-
variables where possible, and use unique names where necessary.
116-
Prefixing variables with the extension name is a good way to
117-
manage the namespace. For example, instead of ``temp_file`` use
118-
``user_scripts_temp_file``. Use ``unset`` to release temporary
119-
variable names when they are no longer needed.
119+
variables where possible, and use unique names where variables
120+
cannot be avoided. Prefixing variables with the extension name is
121+
a good way to manage the namespace. For example, instead of
122+
``temp_file`` use ``user_scripts_temp_file``. Use ``unset`` to
123+
release temporary variable names when they are no longer needed.
120124

121125
.. warning::
122126

@@ -183,8 +187,8 @@ The Hook Loader
183187
---------------
184188

185189
Extensions are run through a command line application implemented in
186-
``virtualenvwrapper.hook_loader``. Since ``virtualenvwrapper.sh`` is
187-
the primary caller and users do not typically need to run the app
190+
``virtualenvwrapper.hook_loader``. Because ``virtualenvwrapper.sh``
191+
is the primary caller and users do not typically need to run the app
188192
directly, no separate script is installed. Instead, to run the
189193
application, use the ``-m`` option to the interpreter::
190194

@@ -199,13 +203,21 @@ application, use the ``-m`` option to the interpreter::
199203
-v, --verbose Show more information on the console
200204
-q, --quiet Show less information on the console
201205

206+
To run the extensions for the initialize hook::
207+
208+
$ python -m virtualenvwrapper.hook_loader -v initialize
209+
210+
To get the shell commands for the initialize hook::
211+
212+
$ python -m virtualenvwrapper.hook_loader --source initialize
213+
202214
Logging
203215
-------
204216

205217
The hook loader configures logging so that messages are written to
206-
``$WORKON_HOME/hook.log``. Messages are also written to stdout,
207-
depending on the verbosity flag. The default is for messages at info
208-
or higher levels to be written to stdout, and debug or higher to go to
218+
``$WORKON_HOME/hook.log``. Messages also may be written to stderr,
219+
depending on the verbosity flag. The default is for messages at *info*
220+
or higher levels to be written to stderr, and *debug* or higher to go to
209221
the log file. Using logging in this way provides a convenient
210222
mechanism for users to control the verbosity of extensions.
211223

@@ -222,19 +234,24 @@ messages.
222234
log.debug('pre_mkvirtualenv %s', str(args))
223235
# ...
224236

237+
.. seealso::
238+
239+
* `Standard library documentation for logging <http://docs.python.org/library/logging.html>`__
240+
* `PyMOTW for logging <http://www.doughellmann.com/PyMOTW/logging/>`__
241+
225242
.. _plugins-extension-points:
226243

227244
Extension Points
228245
================
229246

230-
The extension point names for native plugins are different from the
231-
user customization scripts. The pattern is
232-
``virtualenvwrapper.(pre|post)_event[_source]``. The *event* is the
233-
action taken by the user or virtualenvwrapper that triggers the
234-
extension. ``(pre|post)`` is the prefix indicating whether to call
235-
the extension before or after the event. The suffix ``_source`` is
236-
added for extensions that return shell code instead of taking action
237-
directly (see :ref:`plugins-user-env`).
247+
The extension point names for native plugins follow a naming
248+
convention with several parts:
249+
``virtualenvwrapper.(pre|post)_<event>[_source]``. The *<event>* is
250+
the action taken by the user or virtualenvwrapper that triggers the
251+
extension. ``(pre|post)`` indicates whether to call the extension
252+
before or after the event. The suffix ``_source`` is added for
253+
extensions that return shell code instead of taking action directly
254+
(see :ref:`plugins-user-env`).
238255

239256
.. _plugins-initialize:
240257

0 commit comments

Comments
 (0)