~bzr-pqm/bzr/bzr.dev

1861.2.6 by Alexander Belchenko
branding: change Bazaar-NG to Bazaar
1
==============
2
Bazaar plugins
3
==============
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
4
1861.2.6 by Alexander Belchenko
branding: change Bazaar-NG to Bazaar
5
Information on how to use plugins in Bazaar.
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
6
1610.2.1 by James Blackwell
Copied in docs for wiki & First round cleanup
7
What is a Plugin
8
================
1861.2.6 by Alexander Belchenko
branding: change Bazaar-NG to Bazaar
9
A plugin is an external component for Bazaar that is typically made by
2293.1.3 by Brad Crittenden
Updated version_info.txt for grammar changes
10
third parties. A plugin is capable of augmenting Bazaar by adding new
11
functionality.  A plugin can also change current Bazaar behavior by
12
replacing current functionality. Plugins often work as a way for
13
developers to test new features for Bazaar prior to inclusion in the
14
official codebase. Plugins can do a variety of things, including
1610.2.1 by James Blackwell
Copied in docs for wiki & First round cleanup
15
overriding commands, adding new commands, providing additional network
2293.1.3 by Brad Crittenden
Updated version_info.txt for grammar changes
16
transports, or customizing log output. The sky is the limit for the
2293.1.6 by Brad Crittenden
post review changes
17
customization that can be done through plugins.
1610.2.1 by James Blackwell
Copied in docs for wiki & First round cleanup
18
19
Where to find Plugins 
20
=====================
2293.1.3 by Brad Crittenden
Updated version_info.txt for grammar changes
21
We keep our list of plugins on the http://bazaar-vcs.org/BzrPlugins page.
1610.2.1 by James Blackwell
Copied in docs for wiki & First round cleanup
22
2601.1.3 by James Westby
Put plugin installation instructions before how to write them.
23
How to Install a plugin 
24
=======================
25
Installing a plugin is very easy! One can either install a plugin
26
system-wide or on a per user basis. Both methods involve creating a
27
``plugins`` directory. Within this directory one can place plugins in
28
subdirectories. For example, ``plugins/bzrtools/``.
29
30
Two locations are currently checked:  the bzrlib/plugins directory
31
(typically found in ``/usr/lib/python2.4/site-packages/bzrlib/plugins/``) and
32
``$HOME/.bazaar/plugins/``.
33
34
One can additionally override the home plugins by setting the environment
35
variable ``BZR_PLUGIN_PATH`` to a directory that contains plugins. The
36
installation of a plugin can be checked by running ``bzr plugins`` at
37
any time. New commands can be seen by running ``bzr help commands``.
38
The commands provided by a plugin are shown followed by the name of the
39
plugin in brackets.
40
41
Plugins work particularly well with Bazaar branches. For example, to
42
install the bzrtools plugins for your main user account, one can perform
43
the following:: 
44
45
    bzr branch http://panoramicfeedback.com/opensource/bzr/bzrtools
46
    ~/.bazaar/plugins/bzrtools
47
48
When installing plugins the directories that you install them in must
49
be valid python identifiers. This means that they can only contain
50
certain characters, notably they cannot contain hyphens (``-``). Rather
51
than installing ``bzr-gtk`` to ``~/.bazaar/plugins/bzr-gtk``, install it
52
to ``~/.bazaar/plugins/gtk``.
53
1610.2.1 by James Blackwell
Copied in docs for wiki & First round cleanup
54
Writing a plugin
55
================
56
Plugins are very similar to bzr core functionality.  They can import
57
anything in bzrlib.  A plugin may simply override standard functionality,
58
but most plugins supply new commands.
59
60
To create a command, make a new object that derives from
2293.1.3 by Brad Crittenden
Updated version_info.txt for grammar changes
61
``bzrlib.commands.Command``, and name it ``cmd_foo``, where foo is the name of
1610.2.1 by James Blackwell
Copied in docs for wiki & First round cleanup
62
your command.  If you create a command whose name contains an underscore,
63
it will appear in the UI with the underscore turned into a hyphen.  For
2293.1.3 by Brad Crittenden
Updated version_info.txt for grammar changes
64
example, `cmd_baz_import` will appear as `baz-import`.  For examples of how
65
to write commands, please see ``builtins.py``.
1610.2.1 by James Blackwell
Copied in docs for wiki & First round cleanup
66
67
Once you've created a command you must register the command with
2293.1.3 by Brad Crittenden
Updated version_info.txt for grammar changes
68
``bzrlib.commands.register_command(cmd_foo)``.  You must register the
69
command when your file is imported, otherwise bzr will not see it.
1610.2.1 by James Blackwell
Copied in docs for wiki & First round cleanup
70
2293.1.3 by Brad Crittenden
Updated version_info.txt for grammar changes
71
Bzr will scan ``bzrlib/plugins`` and ``~/.bazaar/plugins`` for plugins
72
by default.  You can override this with ``BZR_PLUGIN_PATH``.  Plugins
73
may be either modules or packages.  If your plugin is a single file,
74
you can structure it as a module.  If it has multiple files, or if you
75
want to distribute it as a bzr branch, you should structure it as a
76
package, i.e. a directory with an ``__init__.py`` file.
1610.2.1 by James Blackwell
Copied in docs for wiki & First round cleanup
77
78
Please feel free to contribute your plugin to BzrTools, if you think it
79
would be useful to other people.
80