~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to doc/developers/plugin-api.txt

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Plugin API
3
3
==========
4
4
 
5
 
Status
6
 
======
7
 
 
8
 
:Date: 2008-02-29
 
5
 
 
6
 
 
7
:Date: 2009-01-23
 
8
 
 
9
.. contents::
 
10
 
 
11
Introduction
 
12
============
9
13
 
10
14
bzrlib has a very flexible internal structure allowing plugins for many
11
15
operations. Plugins can add commands, new storage formats, diff and merge
12
16
features and more. This document provides an overview of the API and
13
17
conventions for plugin authors.
14
18
 
15
 
.. contents::
 
19
If you're writing a plugin and have questions not addressed by this
 
20
document, please ask us.
 
21
 
 
22
See also
 
23
--------
 
24
 
 
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.
16
28
 
17
29
 
18
30
Structure of a plugin
97
109
| bzr_repository_formats | {}      | As bzr_checkout_formats but for        |
98
110
|                        |         | repositories.                          |
99
111
+------------------------+---------+----------------------------------------+
 
112
| bzr_transports         | []      | URL prefixes for which this plugin     |
 
113
|                        |         | will register transports.              |
 
114
+------------------------+---------+----------------------------------------+
100
115
 
101
116
Control Formats
102
117
---------------
113
128
 
114
129
  # (look for a .hg directory)
115
130
  bzr_control_formats = {"Mercurial":{'.hg/': None}}
116
 
  
 
131
 
117
132
  # (look for a file called .svn/format with contents 4\n).
118
133
  bzr_control_formats = {"Subversion":{'.svn/format': '4\n'}}
119
134
 
122
137
-------
123
138
 
124
139
An example setup.py follows::
125
 
  
 
140
 
126
141
  #!/usr/bin/env python2.4
127
142
  from distutils.core import setup
128
 
  
 
143
 
129
144
  bzr_plugin_name = 'demo'
130
145
  bzr_commands = [
131
146
      'new-command',
132
147
      ]
133
 
  
 
148
 
134
149
  bzr_branch_formats = {
135
150
      "Branch label on disk\n":"demo branch",
136
151
      }
137
152
 
138
153
  bzr_control_formats = {"Subversion":{'.svn/format': '4\n'}}
139
 
  
 
154
 
 
155
  bzr_transports = ["hg+ssh://"]
 
156
 
140
157
  bzr_plugin_version = (1, 3, 0, 'dev', 0)
141
158
  bzr_minimum_version = (1, 0, 0)
142
 
  
 
159
 
143
160
  if __name__ == 'main':
144
161
      setup(name="Demo",
145
162
            version="1.3.0dev0",
157
174
Plugin metadata after installation
158
175
==================================
159
176
 
160
 
After a plugin has been installed, metadata can be more easily obtained.
161
 
Currently the only metadata used is for API versioning.
 
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``.
 
180
 
 
181
Help and documentation
 
182
----------------------
 
183
 
 
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``.
 
188
 
 
189
This is a user-visible docstring so should be prefixed with ``__doc__ =``
 
190
to ensure help works under ``python -OO`` with docstrings stripped.
162
191
 
163
192
API version
164
193
-----------
165
194
 
166
 
Please see `API versioning <api-versioning.html>`_ for details on the API
 
195
Plugins can and should declare that they depend on a particular version of
 
196
bzrlib like so::
 
197
 
 
198
    from bzrlib.api import require_api
 
199
 
 
200
    require_api(bzrlib, (1, 11, 0))
 
201
 
 
202
Please see `API versioning <api-versioning.html>`_ for more details on the API
167
203
metadata protocol used by bzrlib.
168
204
 
 
205
Plugin version
 
206
--------------
 
207
 
 
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::
 
211
 
 
212
    version_info = (1, 10, 0)
 
213
 
 
214
 
 
215
Detecting whether code's being loaded as a plugin
 
216
-------------------------------------------------
 
217
 
 
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::
 
221
 
 
222
    if __name__ == 'bzrlib.plugins.loggerhead':
 
223
        # register with bzrlib...
 
224
 
 
225
 
 
226
Plugin performance
 
227
==================
 
228
 
 
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.
 
234
 
 
235
 
 
236
Plugin registrations
 
237
====================
 
238
 
 
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.
 
242
 
 
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>`_.
 
245
 
 
246
 
 
247
Publishing your plugin
 
248
======================
 
249
 
 
250
When your plugin is basically working you might like to share it with
 
251
other people.  Here are some steps to consider:
 
252
 
 
253
 * make a project on Launchpad.net like
 
254
   <https://launchpad.net/bzr-fastimport>
 
255
   and publish the branches or tarballs there
 
256
 
 
257
 * include the plugin in <http://wiki.bazaar.canonical.com/BzrPlugins>
 
258
 
 
259
 * post about it to the ``bazaar-announce`` list at ``lists.canonical.com``
169
260
 
170
261
..
171
 
   vim: ft=rst tw=74 ai
172
 
 
173
 
 
 
262
   vim: ft=rst tw=74 ai shiftwidth=4