2977.1.1
by Ian Clatworthy
First cut at new look User Guide including chapters 1 and 2 |
1 |
Writing a plugin |
2 |
================ |
|
3 |
||
4 |
Introduction |
|
5 |
------------ |
|
6 |
||
7 |
Plugins are very similar to bzr core functionality. They can import |
|
8 |
anything in bzrlib. A plugin may simply override standard functionality, |
|
9 |
but most plugins supply new commands. |
|
10 |
||
11 |
Creating a new command |
|
12 |
---------------------- |
|
13 |
||
14 |
To create a command, make a new object that derives from |
|
15 |
``bzrlib.commands.Command``, and name it ``cmd_foo``, where foo is the name of |
|
16 |
your command. If you create a command whose name contains an underscore, |
|
17 |
it will appear in the UI with the underscore turned into a hyphen. For |
|
18 |
example, `cmd_baz_import` will appear as `baz-import`. For examples of how |
|
19 |
to write commands, please see ``builtins.py``. |
|
20 |
||
21 |
Once you've created a command you must register the command with |
|
22 |
``bzrlib.commands.register_command(cmd_foo)``. You must register the |
|
23 |
command when your file is imported, otherwise bzr will not see it. |
|
24 |
||
3777.6.2
by Marius Kruger
Give an indication of how to specify a plugin version number |
25 |
Specifying a plugin version number |
26 |
---------------------------------- |
|
27 |
Simply define ``version_info`` to be a tuple defining the current version |
|
28 |
number of your plugin. eg. |
|
29 |
``version_info = (0, 9, 0)`` |
|
30 |
``version_info = (0, 9, 0, 'dev', 0)`` |
|
31 |
||
2977.1.1
by Ian Clatworthy
First cut at new look User Guide including chapters 1 and 2 |
32 |
Plugin searching rules |
33 |
---------------------- |
|
34 |
||
4628.2.3
by Vincent Ladeuil
Update doc and add NEWS entry. |
35 |
Bzr will scan ``~/.bazaar/plugins`` and ``bzrlib/plugins`` for plugins |
36 |
by default. You can override this with ``BZR_PLUGIN_PATH`` |
|
37 |
(see `User Reference <../user-reference/bzr_man.html#bzr-plugin-path>`_ |
|
38 |
for details). |
|
39 |
||
40 |
Plugins may be either modules or packages. If your plugin is a single |
|
41 |
file, you can structure it as a module. If it has multiple files, or if |
|
42 |
you want to distribute it as a bzr branch, you should structure it as a |
|
2977.1.1
by Ian Clatworthy
First cut at new look User Guide including chapters 1 and 2 |
43 |
package, i.e. a directory with an ``__init__.py`` file. |
44 |
||
45 |
More information |
|
46 |
---------------- |
|
47 |
||
48 |
Please feel free to contribute your plugin to BzrTools, if you think it |
|
49 |
would be useful to other people. |
|
50 |
||
51 |
See the `Bazaar Developer Guide`_ for details on Bazaar's development |
|
52 |
guidelines and policies. |
|
53 |
||
54 |
.. _Bazaar Developer Guide: ../developer-guide/HACKING.html |