14
10
bzrlib has a very flexible internal structure allowing plugins for many
15
11
operations. Plugins can add commands, new storage formats, diff and merge
16
12
features and more. This document provides an overview of the API and
17
13
conventions for plugin authors.
19
If you're writing a plugin and have questions not addressed by this
20
document, please ask us.
25
* `Bazaar Developer Documentation Catalog <../index.html>`_.
26
* `Bazaar Plugins Guide <http://doc.bazaar.canonical.com/plugins/en/plugin-development.html>`_ for
27
more suggestions about particular APIs.
30
18
Structure of a plugin
139
124
An example setup.py follows::
141
126
#!/usr/bin/env python2.4
142
127
from distutils.core import setup
144
129
bzr_plugin_name = 'demo'
149
134
bzr_branch_formats = {
150
135
"Branch label on disk\n":"demo branch",
153
138
bzr_control_formats = {"Subversion":{'.svn/format': '4\n'}}
155
bzr_transports = ["hg+ssh://"]
157
140
bzr_plugin_version = (1, 3, 0, 'dev', 0)
158
141
bzr_minimum_version = (1, 0, 0)
160
143
if __name__ == 'main':
161
144
setup(name="Demo",
162
145
version="1.3.0dev0",
174
157
Plugin metadata after installation
175
158
==================================
177
After a plugin has been installed, metadata can be more easily obtained by
178
looking inside the module object -- in other words, for variables defined
179
in the plugin's ``__init__.py``.
181
Help and documentation
182
----------------------
184
The module docstring is used as the plugin description shown by ``bzr
185
plugins``. As with all Python docstrings, the first line should be a
186
short complete sentence summarizing the plugin. The full docstring is
187
shown by ``bzr help PLUGIN_NAME``.
189
This is a user-visible docstring so should be prefixed with ``__doc__ =``
190
to ensure help works under ``python -OO`` with docstrings stripped.
160
After a plugin has been installed, metadata can be more easily obtained.
161
Currently the only metadata used is for API versioning.
195
Plugins can and should declare that they depend on a particular version of
198
from bzrlib.api import require_api
200
require_api(bzrlib, (1, 11, 0))
202
Please see `API versioning <api-versioning.html>`_ for more details on the API
166
Please see `API versioning <api-versioning.html>`_ for details on the API
203
167
metadata protocol used by bzrlib.
208
The plugin should expose a version tuple to describe its own version.
209
Some plugins use a version number that corresponds to the version of bzr
210
they're released against, but you can use whatever you want. For example::
212
version_info = (1, 10, 0)
215
Detecting whether code's being loaded as a plugin
216
-------------------------------------------------
218
You may have a Python module that can be used as a bzr plugin and also in
219
other places. To detect whether the module is being loaded by bzr, use
220
something like this::
222
if __name__ == 'bzrlib.plugins.loggerhead':
223
# register with bzrlib...
229
Plugins should avoid doing work or loading code from the plugin or
230
external libraries, if they're just installed but not actually active,
231
because this slows down every invocation of bzr. The bzrlib APIs
232
generally allow the plugin to 'lazily' register methods to invoke if a
233
particular disk format or seen or a particular command is run.
239
The plugin ``__init__.py`` runs when the plugin is loaded during bzr
240
startup. Generally the plugin won't want to actually do anything at this
241
time other than register or override functions to be called later.
243
The plugin can import bzrlib and call any function.
244
Some interesting APIs are described in `Bazaar Plugins Guide <http://doc.bazaar.canonical.com/plugins/en/plugin-development.html>`_.
247
Publishing your plugin
248
======================
250
When your plugin is basically working you might like to share it with
251
other people. Here are some steps to consider:
253
* make a project on Launchpad.net like
254
<https://launchpad.net/bzr-fastimport>
255
and publish the branches or tarballs there
257
* include the plugin in <http://wiki.bazaar.canonical.com/BzrPlugins>
259
* post about it to the ``bazaar-announce`` list at ``lists.canonical.com``
262
vim: ft=rst tw=74 ai shiftwidth=4