76
61
Bazaar Development in a Nutshell
77
62
================================
79
.. was from bazaar-vcs.org/BzrGivingBack
81
One of the fun things about working on a version control system like Bazaar is
82
that the users have a high level of proficiency in contributing back into
83
the tool. Consider the following very brief introduction to contributing back
84
to Bazaar. More detailed instructions are in the following sections.
89
First, get a local copy of the development mainline (See `Why make a local
95
$ bzr branch http://bazaar-vcs.org/bzr/bzr.dev/ bzr.dev
97
Now make your own branch::
99
$ bzr branch bzr.dev 123456-my-bugfix
101
This will give you a branch called "123456-my-bugfix" that you can work on
102
and commit in. Here, you can study the code, make a fix or a new feature.
103
Feel free to commit early and often (after all, it's your branch!).
105
Documentation improvements are an easy place to get started giving back to the
106
Bazaar project. The documentation is in the `doc/` subdirectory of the Bazaar
109
When you are done, make sure that you commit your last set of changes as well!
110
Once you are happy with your changes, ask for them to be merged, as described
113
Making a Merge Proposal
114
-----------------------
116
The Bazaar developers use Launchpad to further enable a truly distributed
117
style of development. Anyone can propose a branch for merging into the Bazaar
118
trunk. To start this process, you need to push your branch to Launchpad. To
119
do this, you will need a Launchpad account and user name, e.g.
120
`your_lp_username`. You can push your branch to Launchpad directly from
123
$ bzr push lp:~your_lp_username/bzr/meaningful_name_here
125
After you have pushed your branch, you will need to propose it for merging to
126
the Bazaar trunk. Go to
127
<https://launchpad.net/your_lp_username/bzr/meaningful_name_here> and choose
128
"Propose for merging into another branch". Select "~bzr/bzr/trunk" to hand
129
your changes off to the Bazaar developers for review and merging.
131
Using a meaningful name for your branch will help you and the reviewer(s)
132
better track the submission. Use a very succint description of your submission
133
and prefix it with bug number if needed (lp:~mbp/bzr/484558-merge-directory
134
for example). Alternatively, you can suffix with the bug number
135
(lp:~jameinel/bzr/export-file-511987).
138
Why make a local copy of bzr.dev?
139
---------------------------------
141
Making a local mirror of bzr.dev is not strictly necessary, but it means
143
- You can use that copy of bzr.dev as your main bzr executable, and keep it
144
up-to-date using ``bzr pull``.
145
- Certain operations are faster, and can be done when offline. For example:
148
- ``bzr diff -r ancestor:...``
151
- When it's time to create your next branch, it's more convenient. When you
152
have further contributions to make, you should do them in their own branch::
155
$ bzr branch bzr.dev additional_fixes
156
$ cd additional_fixes # hack, hack, hack
64
Looking for a 10 minute introduction to submitting a change?
65
See http://bazaar-vcs.org/BzrGivingBack.
67
TODO: Merge that Wiki page into this document.
160
70
Understanding the Development Process
161
71
=====================================
163
The development team follows many practices including:
73
The development team follows many best-practices including:
165
75
* a public roadmap and planning process in which anyone can participate
186
96
For further information, see http://bazaar-vcs.org/BzrDevelopment.
191
Preparing a Sandbox for Making Changes to Bazaar
192
================================================
194
Bazaar supports many ways of organising your work. See
195
http://bazaar-vcs.org/SharedRepositoryLayouts for a summary of the
196
popular alternatives.
198
Of course, the best choice for you will depend on numerous factors:
199
the number of changes you may be making, the complexity of the changes, etc.
200
As a starting suggestion though:
202
* create a local copy of the main development branch (bzr.dev) by using
205
bzr branch http://bazaar-vcs.org/bzr/bzr.dev/ bzr.dev
207
* keep your copy of bzr.dev pristine (by not developing in it) and keep
208
it up to date (by using bzr pull)
210
* create a new branch off your local bzr.dev copy for each issue
211
(bug or feature) you are working on.
213
This approach makes it easy to go back and make any required changes
214
after a code review. Resubmitting the change is then simple with no
215
risk of accidentally including edits related to other issues you may
216
be working on. After the changes for an issue are accepted and merged,
217
the associated branch can be deleted or archived as you wish.
220
Navigating the Code Base
221
========================
223
.. Was at <http://bazaar-vcs.org/NewDeveloperIntroduction>
225
Some of the key files in this directory are:
228
The command you run to start Bazaar itself. This script is pretty
229
short and just does some checks then jumps into bzrlib.
232
This file covers a brief introduction to Bazaar and lists some of its
236
Summary of changes in each Bazaar release that can affect users or
240
Installs Bazaar system-wide or to your home directory. To perform
241
development work on Bazaar it is not required to run this file - you
242
can simply run the bzr command from the top level directory of your
243
development copy. Note: That if you run setup.py this will create a
244
'build' directory in your development branch. There's nothing wrong
245
with this but don't be confused by it. The build process puts a copy
246
of the main code base into this build directory, along with some other
247
files. You don't need to go in here for anything discussed in this
251
Possibly the most exciting folder of all, bzrlib holds the main code
252
base. This is where you will go to edit python files and contribute to
256
Holds documentation on a whole range of things on Bazaar from the
257
origination of ideas within the project to information on Bazaar
258
features and use cases. Within this directory there is a subdirectory
259
for each translation into a human language. All the documentation
260
is in the ReStructuredText markup language.
263
Documentation specifically targeted at Bazaar and plugin developers.
264
(Including this document.)
268
Automatically-generated API reference information is available at
269
<http://starship.python.net/crew/mwh/bzrlibapi/>.
271
See also the `Bazaar Architectural Overview
272
<http://doc.bazaar-vcs.org/developers/overview.html>`_.
275
The Code Review Process
276
#######################
278
All code changes coming in to Bazaar are reviewed by someone else.
279
Normally changes by core contributors are reviewed by one other core
280
developer, and changes from other people are reviewed by two core
281
developers. Use intelligent discretion if the patch is trivial.
283
Good reviews do take time. They also regularly require a solid
284
understanding of the overall code base. In practice, this means a small
285
number of people often have a large review burden - with knowledge comes
286
responsibility. No one likes their merge requests sitting in a queue going
287
nowhere, so reviewing sooner rather than later is strongly encouraged.
296
Please put a "cover letter" on your merge request explaining:
298
* the reason **why** you're making this change
300
* **how** this change achieves this purpose
302
* anything else you may have fixed in passing
304
* anything significant that you thought of doing, such as a more
305
extensive fix or a different approach, but didn't or couldn't do now
307
A good cover letter makes reviewers' lives easier because they can decide
308
from the letter whether they agree with the purpose and approach, and then
309
assess whether the patch actually does what the cover letter says.
310
Explaining any "drive-by fixes" or roads not taken may also avoid queries
311
from the reviewer. All in all this should give faster and better reviews.
312
Sometimes writing the cover letter helps the submitter realize something
313
else they need to do. The size of the cover letter should be proportional
314
to the size and complexity of the patch.
317
Reviewing proposed changes
318
==========================
320
Anyone is welcome to review code, and reply to the thread with their
323
The simplest way to review a proposed change is to just read the patch on
324
the list or in Bundle Buggy. For more complex changes it may be useful
325
to make a new working tree or branch from trunk, and merge the proposed
326
change into it, so you can experiment with the code or look at a wider
329
There are three main requirements for code to get in:
331
* Doesn't reduce test coverage: if it adds new methods or commands,
332
there should be tests for them. There is a good test framework
333
and plenty of examples to crib from, but if you are having trouble
334
working out how to test something feel free to post a draft patch
337
* Doesn't reduce design clarity, such as by entangling objects
338
we're trying to separate. This is mostly something the more
339
experienced reviewers need to help check.
341
* Improves bugs, features, speed, or code simplicity.
343
Code that goes in should not degrade any of these aspects. Patches are
344
welcome that only cleanup the code without changing the external
345
behaviour. The core developers take care to keep the code quality high
346
and understandable while recognising that perfect is sometimes the enemy
349
It is easy for reviews to make people notice other things which should be
350
fixed but those things should not hold up the original fix being accepted.
351
New things can easily be recorded in the Bug Tracker instead.
353
It's normally much easier to review several smaller patches than one large
354
one. You might want to use ``bzr-loom`` to maintain threads of related
355
work, or submit a preparatory patch that will make your "real" change
359
Checklist for reviewers
360
=======================
362
* Do you understand what the code's doing and why?
364
* Will it perform reasonably for large inputs, both in memory size and
365
run time? Are there some scenarios where performance should be
368
* Is it tested, and are the tests at the right level? Are there both
369
blackbox (command-line level) and API-oriented tests?
371
* If this change will be visible to end users or API users, is it
372
appropriately documented in NEWS?
374
* Does it meet the coding standards below?
376
* If it changes the user-visible behaviour, does it update the help
377
strings and user documentation?
379
* If it adds a new major concept or standard practice, does it update the
380
developer documentation?
382
* (your ideas here...)
388
From May 2009 on, we prefer people to propose code reviews through
391
* <https://launchpad.net/+tour/code-review>
393
* <https://help.launchpad.net/Code/Review>
395
Anyone can propose or comment on a merge proposal just by creating a
398
There are two ways to create a new merge proposal: through the web
399
interface or by email.
402
Proposing a merge through the web
403
---------------------------------
405
To create the proposal through the web, first push your branch to Launchpad.
406
For example, a branch dealing with documentation belonging to the Launchpad
407
User mbp could be pushed as ::
409
bzr push lp:~mbp/bzr/doc
411
Then go to the branch's web page, which in this case would be
412
<https://code.launchpad.net/~mbp/bzr/doc>. You can simplify this step by just
417
You can then click "Propose for merging into another branch", and enter your
418
cover letter (see above) into the web form. Typically you'll want to merge
419
into ``~bzr/bzr/trunk`` which will be the default; you might also want to
420
nominate merging into a release branch for a bug fix. There is the option to
421
specify a specific reviewer or type of review, and you shouldn't normally
424
Submitting the form takes you to the new page about the merge proposal
425
containing the diff of the changes, comments by interested people, and
426
controls to comment or vote on the change.
428
Proposing a merge by mail
429
-------------------------
431
To propose a merge by mail, send a bundle to ``merge@code.launchpad.net``.
433
You can generate a merge request like this::
435
bzr send -o bug-1234.diff
437
``bzr send`` can also send mail directly if you prefer; see the help.
442
From <https://code.launchpad.net/bzr/+activereviews> you can see all
443
currently active reviews, and choose one to comment on. This page also
444
shows proposals that are now approved and should be merged by someone with
448
Reviews through Bundle Buggy
449
============================
451
The Bundle Buggy tool used up to May 2009 is still available as a review
454
Sending patches for review
455
--------------------------
99
A Closer Look at the Merge & Review Process
100
===========================================
457
102
If you'd like to propose a change, please post to the
458
103
bazaar@lists.canonical.com list with a bundle, patch, or link to a
459
branch. Put ``[PATCH]`` or ``[MERGE]`` in the subject so Bundle Buggy
104
branch. Put '[PATCH]' or '[MERGE]' in the subject so Bundle Buggy
460
105
can pick it out, and explain the change in the email message text.
461
106
Remember to update the NEWS file as part of your change if it makes any
462
107
changes visible to users or plugin developers. Please include a diff
463
108
against mainline if you're giving a link to a branch.
465
You can generate a merge request like this::
467
bzr send -o bug-1234.patch
469
A ``.patch`` extension is recommended instead of .bundle as many mail clients
470
will send the latter as a binary file.
472
``bzr send`` can also send mail directly if you prefer; see the help.
110
You can generate a bundle like this::
112
bzr bundle > mybundle.patch
114
A .patch extension is recommended instead of .bundle as many mail clients
115
will send the latter as a binary file. If a bundle would be too long or your
116
mailer mangles whitespace (e.g. implicitly converts Unix newlines to DOS
117
newlines), use the merge-directive command instead like this::
119
bzr merge-directive http://bazaar-vcs.org http://example.org/my_branch > my_directive.patch
121
See the help for details on the arguments to merge-directive.
474
123
Please do **NOT** put [PATCH] or [MERGE] in the subject line if you don't
475
124
want it to be merged. If you want comments from developers rather than
476
to be merged, you can put ``[RFC]`` in the subject line.
478
If this change addresses a bug, please put the bug number in the subject
479
line too, in the form ``[#1]`` so that Bundle Buggy can recognize it.
481
If the change is intended for a particular release mark that in the
482
subject too, e.g. ``[1.6]``.
483
Anyone can "vote" on the mailing list by expressing an opinion. Core
484
developers can also vote using Bundle Buggy. Here are the voting codes and
125
to be merged, you can put '[RFC]' in the subject line.
127
Anyone is welcome to review code. There are broadly three gates for
130
* Doesn't reduce test coverage: if it adds new methods or commands,
131
there should be tests for them. There is a good test framework
132
and plenty of examples to crib from, but if you are having trouble
133
working out how to test something feel free to post a draft patch
136
* Doesn't reduce design clarity, such as by entangling objects
137
we're trying to separate. This is mostly something the more
138
experienced reviewers need to help check.
140
* Improves bugs, features, speed, or code simplicity.
142
Code that goes in should pass all three. The core developers take care
143
to keep the code quality high and understandable while recognising that
144
perfect is sometimes the enemy of good. (It is easy for reviews to make
145
people notice other things which should be fixed but those things should
146
not hold up the original fix being accepted. New things can easily be
147
recorded in the Bug Tracker instead.)
149
Anyone can "vote" on the mailing list. Core developers can also vote using
150
Bundle Buggy. Here are the voting codes and their explanations.
487
152
:approve: Reviewer wants this submission merged.
488
153
:tweak: Reviewer wants this submission merged with small changes. (No
505
170
outstanding merge requests together with an explanation of the columns.
506
171
Bundle Buggy will also mail you a link to track just your change.
174
Preparing a Sandbox for Making Changes to Bazaar
175
================================================
177
Bazaar supports many ways of organising your work. See
178
http://bazaar-vcs.org/SharedRepositoryLayouts for a summary of the
179
popular alternatives.
181
Of course, the best choice for you will depend on numerous factors:
182
the number of changes you may be making, the complexity of the changes, etc.
183
As a starting suggestion though:
185
* create a local copy of the main development branch (bzr.dev) by using
188
bzr branch http://bazaar-vcs.org/bzr/bzr.dev/ bzr.dev
190
* keep your copy of bzr.dev prestine (by not developing in it) and keep
191
it up to date (by using bzr pull)
193
* create a new branch off your local bzr.dev copy for each issue
194
(bug or feature) you are working on.
196
This approach makes it easy to go back and make any required changes
197
after a code review. Resubmitting the change is then simple with no
198
risk of accidentially including edits related to other issues you may
199
be working on. After the changes for an issue are accepted and merged,
200
the associated branch can be deleted or archived as you wish.
203
Navigating the Code Base
204
========================
206
TODO: List and describe in one line the purpose of each directory
207
inside an installation of bzr.
209
TODO: Refer to a central location holding an up to date copy of the API
210
documentation generated by epydoc, e.g. something like
211
http://starship.python.net/crew/mwh/bzrlibapi/bzrlib.html.
217
The Importance of Testing
218
=========================
220
Reliability is a critical success factor for any Version Control System.
221
We want Bazaar to be highly reliable across multiple platforms while
222
evolving over time to meet the needs of its community.
224
In a nutshell, this is want we expect and encourage:
226
* New functionality should have test cases. Preferably write the
227
test before writing the code.
229
In general, you can test at either the command-line level or the
230
internal API level. See Writing tests below for more detail.
232
* Try to practice Test-Driven Development: before fixing a bug, write a
233
test case so that it does not regress. Similarly for adding a new
234
feature: write a test case for a small version of the new feature before
235
starting on the code itself. Check the test fails on the old code, then
236
add the feature or fix and check it passes.
238
By doing these things, the Bazaar team gets increased confidence that
239
changes do what they claim to do, whether provided by the core team or
240
by community members. Equally importantly, we can be surer that changes
241
down the track do not break new features or bug fixes that you are
244
As of May 2007, Bazaar ships with a test suite containing over 6000 tests
245
and growing. We are proud of it and want to remain so. As community
246
members, we all benefit from it. Would you trust version control on
247
your project to a product *without* a test suite like Bazaar has?
250
Running the Test Suite
251
======================
253
Currently, bzr selftest is used to invoke tests.
254
You can provide a pattern argument to run a subset. For example,
255
to run just the blackbox tests, run::
257
./bzr selftest -v blackbox
259
To skip a particular test (or set of tests), use the --exclude option
260
(shorthand -x) like so::
262
./bzr selftest -v -x blackbox
264
To list tests without running them, use the --list-only option like so::
266
./bzr selftest --list-only
268
This option can be combined with other selftest options (like -x) and
269
filter patterns to understand their effect.
275
In general tests should be placed in a file named test_FOO.py where
276
FOO is the logical thing under test. That file should be placed in the
277
tests subdirectory under the package being tested.
279
For example, tests for merge3 in bzrlib belong in bzrlib/tests/test_merge3.py.
280
See bzrlib/tests/test_sampler.py for a template test script.
282
Tests can be written for the UI or for individual areas of the library.
283
Choose whichever is appropriate: if adding a new command, or a new command
284
option, then you should be writing a UI test. If you are both adding UI
285
functionality and library functionality, you will want to write tests for
286
both the UI and the core behaviours. We call UI tests 'blackbox' tests
287
and they are found in ``bzrlib/tests/blackbox/*.py``.
289
When writing blackbox tests please honour the following conventions:
291
1. Place the tests for the command 'name' in
292
bzrlib/tests/blackbox/test_name.py. This makes it easy for developers
293
to locate the test script for a faulty command.
295
2. Use the 'self.run_bzr("name")' utility function to invoke the command
296
rather than running bzr in a subprocess or invoking the
297
cmd_object.run() method directly. This is a lot faster than
298
subprocesses and generates the same logging output as running it in a
299
subprocess (which invoking the method directly does not).
301
3. Only test the one command in a single test script. Use the bzrlib
302
library when setting up tests and when evaluating the side-effects of
303
the command. We do this so that the library api has continual pressure
304
on it to be as functional as the command line in a simple manner, and
305
to isolate knock-on effects throughout the blackbox test suite when a
306
command changes its name or signature. Ideally only the tests for a
307
given command are affected when a given command is changed.
309
4. If you have a test which does actually require running bzr in a
310
subprocess you can use ``run_bzr_subprocess``. By default the spawned
311
process will not load plugins unless ``--allow-plugins`` is supplied.
317
We make selective use of doctests__. In general they should provide
318
*examples* within the API documentation which can incidentally be tested. We
319
don't try to test every important case using doctests -- regular Python
320
tests are generally a better solution.
322
Most of these are in ``bzrlib/doc/api``. More additions are welcome.
324
__ http://docs.python.org/lib/module-doctest.html
327
Skipping tests and test requirements
328
------------------------------------
330
In our enhancements to unittest we allow for some addition results beyond
331
just success or failure.
333
If a test can't be run, it can say that it's skipped. This is typically
334
used in parameterized tests - for example if a transport doesn't support
335
setting permissions, we'll skip the tests that relating to that. ::
338
return self.branch_format.initialize(repo.bzrdir)
339
except errors.UninitializableFormat:
340
raise tests.TestSkipped('Uninitializable branch format')
342
Raising TestSkipped is a good idea when you want to make it clear that the
343
test was not run, rather than just returning which makes it look as if it
346
A subtly different case is a test that should run, but can't run in the
347
current environment. This covers tests that can only run in particular
348
operating systems or locales, or that depend on external libraries. Here
349
we want to inform the user that they didn't get full test coverage, but
350
they possibly could if they installed more libraries. These are expressed
351
as a dependency on a feature so we can summarise them, and so that the
352
test for the feature is done only once. (For historical reasons, as of
353
May 2007 many cases that should depend on features currently raise
354
TestSkipped.) The typical use is::
356
class TestStrace(TestCaseWithTransport):
358
_test_needs_features = [StraceFeature]
360
which means all tests in this class need the feature. The feature itself
361
should provide a ``_probe`` method which is called once to determine if
368
Known failures are when a test exists but we know it currently doesn't
369
work, allowing the test suite to still pass. These should be used with
370
care, we don't want a proliferation of quietly broken tests. It might be
371
appropriate to use them if you've committed a test for a bug but not the
372
fix for it, or if something works on Unix but not on Windows.
375
Testing exceptions and errors
376
-----------------------------
378
It's important to test handling of errors and exceptions. Because this
379
code is often not hit in ad-hoc testing it can often have hidden bugs --
380
it's particularly common to get NameError because the exception code
381
references a variable that has since been renamed.
383
.. TODO: Something about how to provoke errors in the right way?
385
In general we want to test errors at two levels:
387
1. A test in ``test_errors.py`` checking that when the exception object is
388
constructed with known parameters it produces an expected string form.
389
This guards against mistakes in writing the format string, or in the
390
``str`` representations of its parameters. There should be one for
391
each exception class.
393
2. Tests that when an api is called in a particular situation, it raises
394
an error of the expected class. You should typically use
395
``assertRaises``, which in the Bazaar test suite returns the exception
396
object to allow you to examine its parameters.
398
In some cases blackbox tests will also want to check error reporting. But
399
it can be difficult to provoke every error through the commandline
400
interface, so those tests are only done as needed -- eg in response to a
401
particular bug or if the error is reported in an unusual way(?) Blackbox
402
tests should mostly be testing how the command-line interface works, so
403
should only test errors if there is something particular to the cli in how
404
they're displayed or handled.
407
Essential Domain Classes
408
########################
410
Introducing the Object Model
411
============================
413
The core domain objects within the bazaar model are:
423
Transports are explained below. See http://bazaar-vcs.org/Classes/
424
for an introduction to the other key classes.
429
The ``Transport`` layer handles access to local or remote directories.
430
Each Transport object acts like a logical connection to a particular
431
directory, and it allows various operations on files within it. You can
432
*clone* a transport to get a new Transport connected to a subdirectory or
435
Transports are not used for access to the working tree. At present
436
working trees are always local and they are accessed through the regular
437
Python file io mechanisms.
442
Transports work in URLs. Take note that URLs are by definition only
443
ASCII - the decision of how to encode a Unicode string into a URL must be
444
taken at a higher level, typically in the Store. (Note that Stores also
445
escape filenames which cannot be safely stored on all filesystems, but
446
this is a different level.)
448
The main reason for this is that it's not possible to safely roundtrip a
449
URL into Unicode and then back into the same URL. The URL standard
450
gives a way to represent non-ASCII bytes in ASCII (as %-escapes), but
451
doesn't say how those bytes represent non-ASCII characters. (They're not
452
guaranteed to be UTF-8 -- that is common but doesn't happen everywhere.)
454
For example if the user enters the url ``http://example/%e0`` there's no
455
way to tell whether that character represents "latin small letter a with
456
grave" in iso-8859-1, or "latin small letter r with acute" in iso-8859-2
457
or malformed UTF-8. So we can't convert their URL to Unicode reliably.
459
Equally problematic if we're given a url-like string containing non-ascii
460
characters (such as the accented a) we can't be sure how to convert that
461
to the correct URL, because we don't know what encoding the server expects
462
for those characters. (Although this is not totally reliable we might still
463
accept these and assume they should be put into UTF-8.)
465
A similar edge case is that the url ``http://foo/sweet%2Fsour`` contains
466
one directory component whose name is "sweet/sour". The escaped slash is
467
not a directory separator. If we try to convert URLs to regular Unicode
468
paths this information will be lost.
470
This implies that Transports must natively deal with URLs; for simplicity
471
they *only* deal with URLs and conversion of other strings to URLs is done
472
elsewhere. Information they return, such as from ``list_dir``, is also in
473
the form of URL components.
482
We have a commitment to 6 months API stability - any supported symbol in a
483
release of bzr MUST NOT be altered in any way that would result in
484
breaking existing code that uses it. That means that method names,
485
parameter ordering, parameter names, variable and attribute names etc must
486
not be changed without leaving a 'deprecated forwarder' behind. This even
487
applies to modules and classes.
489
If you wish to change the behaviour of a supported API in an incompatible
490
way, you need to change its name as well. For instance, if I add an optional keyword
491
parameter to branch.commit - that's fine. On the other hand, if I add a
492
keyword parameter to branch.commit which is a *required* transaction
493
object, I should rename the API - i.e. to 'branch.commit_transaction'.
495
When renaming such supported API's, be sure to leave a deprecated_method (or
496
_function or ...) behind which forwards to the new API. See the
497
bzrlib.symbol_versioning module for decorators that take care of the
498
details for you - such as updating the docstring, and issuing a warning
499
when the old api is used.
501
For unsupported API's, it does not hurt to follow this discipline, but it's
502
not required. Minimally though, please try to rename things so that
503
callers will at least get an AttributeError rather than weird results.
508
506
Coding Style Guidelines
509
#######################
514
``hasattr`` should not be used because it swallows exceptions including
515
``KeyboardInterrupt``. Instead, say something like ::
517
if getattr(thing, 'name', None) is None
523
Please write PEP-8__ compliant code.
525
__ http://www.python.org/peps/pep-0008.html
507
=======================
509
Please write PEP-8__ compliant code.
527
511
One often-missed requirement is that the first line of docstrings
528
512
should be a self-contained one-sentence summary.
530
We use 4 space indents for blocks, and never use tab characters. (In vim,
533
Trailing white space should be avoided, but is allowed.
534
You should however not make lots of unrelated white space changes.
536
Unix style newlines (LF) are used.
538
Each file must have a newline at the end of it.
540
Lines should be no more than 79 characters if at all possible.
541
Lines that continue a long statement may be indented in either of
544
within the parenthesis or other character that opens the block, e.g.::
550
or indented by four spaces::
556
The first is considered clearer by some people; however it can be a bit
557
harder to maintain (e.g. when the method name changes), and it does not
558
work well if the relevant parenthesis is already far to the right. Avoid
561
self.legbone.kneebone.shinbone.toebone.shake_it(one,
567
self.legbone.kneebone.shinbone.toebone.shake_it(one,
573
self.legbone.kneebone.shinbone.toebone.shake_it(
576
For long lists, we like to add a trailing comma and put the closing
577
character on the following line. This makes it easier to add new items in
580
from bzrlib.goo import (
586
There should be spaces between function parameters, but not between the
587
keyword name and the value::
589
call(1, 3, cheese=quark)
593
;(defface my-invalid-face
594
; '((t (:background "Red" :underline t)))
595
; "Face used to highlight invalid constructs or other uglyties"
598
(defun my-python-mode-hook ()
599
;; setup preferred indentation style.
600
(setq fill-column 79)
601
(setq indent-tabs-mode nil) ; no tabs, never, I will not repeat
602
; (font-lock-add-keywords 'python-mode
603
; '(("^\\s *\t" . 'my-invalid-face) ; Leading tabs
604
; ("[ \t]+$" . 'my-invalid-face) ; Trailing spaces
605
; ("^[ \t]+$" . 'my-invalid-face)); Spaces only
609
(add-hook 'python-mode-hook 'my-python-mode-hook)
611
The lines beginning with ';' are comments. They can be activated
612
if one want to have a strong notice of some tab/space usage
514
__ http://www.python.org/peps/pep-0008.html
619
520
* Imports should be done at the top-level of the file, unless there is
620
521
a strong reason to have them lazily loaded when a particular
806
677
being phased out.
809
Object string representations
810
=============================
812
Python prints objects using their ``__repr__`` method when they are
813
written to logs, exception tracebacks, or the debugger. We want
814
objects to have useful representations to help in determining what went
817
If you add a new class you should generally add a ``__repr__`` method
818
unless there is an adequate method in a parent class. There should be a
821
Representations should typically look like Python constructor syntax, but
822
they don't need to include every value in the object and they don't need
823
to be able to actually execute. They're to be read by humans, not
824
machines. Don't hardcode the classname in the format, so that we get the
825
correct value if the method is inherited by a subclass. If you're
826
printing attributes of the object, including strings, you should normally
827
use ``%r`` syntax (to call their repr in turn).
829
Try to avoid the representation becoming more than one or two lines long.
830
(But balance this against including useful information, and simplicity of
833
Because repr methods are often called when something has already gone
834
wrong, they should be written somewhat more defensively than most code.
835
The object may be half-initialized or in some other way in an illegal
836
state. The repr method shouldn't raise an exception, or it may hide the
837
(probably more useful) underlying exception.
842
return '%s(%r)' % (self.__class__.__name__,
849
A bare ``except`` statement will catch all exceptions, including ones that
850
really should terminate the program such as ``MemoryError`` and
851
``KeyboardInterrupt``. They should rarely be used unless the exception is
852
later re-raised. Even then, think about whether catching just
853
``Exception`` (which excludes system errors in Python2.5 and later) would
860
All code should be exercised by the test suite. See the `Bazaar Testing
861
Guide <http://doc.bazaar-vcs.org/developers/testing.html>`_ for detailed
862
information about writing tests.
871
We don't change APIs in stable branches: any supported symbol in a stable
872
release of bzr must not be altered in any way that would result in
873
breaking existing code that uses it. That means that method names,
874
parameter ordering, parameter names, variable and attribute names etc must
875
not be changed without leaving a 'deprecated forwarder' behind. This even
876
applies to modules and classes.
878
If you wish to change the behaviour of a supported API in an incompatible
879
way, you need to change its name as well. For instance, if I add an optional keyword
880
parameter to branch.commit - that's fine. On the other hand, if I add a
881
keyword parameter to branch.commit which is a *required* transaction
882
object, I should rename the API - i.e. to 'branch.commit_transaction'.
884
(Actually, that may break code that provides a new implementation of
885
``commit`` and doesn't expect to receive the parameter.)
887
When renaming such supported API's, be sure to leave a deprecated_method (or
888
_function or ...) behind which forwards to the new API. See the
889
bzrlib.symbol_versioning module for decorators that take care of the
890
details for you - such as updating the docstring, and issuing a warning
891
when the old API is used.
893
For unsupported API's, it does not hurt to follow this discipline, but it's
894
not required. Minimally though, please try to rename things so that
895
callers will at least get an AttributeError rather than weird results.
898
Deprecation decorators
899
----------------------
901
``bzrlib.symbol_versioning`` provides decorators that can be attached to
902
methods, functions, and other interfaces to indicate that they should no
903
longer be used. For example::
905
@deprecated_method(deprecated_in((0, 1, 4)))
907
return self._new_foo()
909
To deprecate a static method you must call ``deprecated_function``
910
(**not** method), after the staticmethod call::
913
@deprecated_function(deprecated_in((0, 1, 4)))
914
def create_repository(base, shared=False, format=None):
916
When you deprecate an API, you should not just delete its tests, because
917
then we might introduce bugs in them. If the API is still present at all,
918
it should still work. The basic approach is to use
919
``TestCase.applyDeprecated`` which in one step checks that the API gives
920
the expected deprecation message, and also returns the real result from
921
the method, so that tests can keep running.
923
Deprecation warnings will be suppressed for final releases, but not for
924
development versions or release candidates, or when running ``bzr
925
selftest``. This gives developers information about whether their code is
926
using deprecated functions, but avoids confusing users about things they
761
In general tests should be placed in a file named test_FOO.py where
762
FOO is the logical thing under test. That file should be placed in the
763
tests subdirectory under the package being tested.
765
For example, tests for merge3 in bzrlib belong in bzrlib/tests/test_merge3.py.
766
See bzrlib/tests/test_sampler.py for a template test script.
768
Tests can be written for the UI or for individual areas of the library.
769
Choose whichever is appropriate: if adding a new command, or a new command
770
option, then you should be writing a UI test. If you are both adding UI
771
functionality and library functionality, you will want to write tests for
772
both the UI and the core behaviours. We call UI tests 'blackbox' tests
773
and they are found in ``bzrlib/tests/blackbox/*.py``.
775
When writing blackbox tests please honour the following conventions:
777
1. Place the tests for the command 'name' in
778
bzrlib/tests/blackbox/test_name.py. This makes it easy for developers
779
to locate the test script for a faulty command.
781
2. Use the 'self.run_bzr("name")' utility function to invoke the command
782
rather than running bzr in a subprocess or invoking the
783
cmd_object.run() method directly. This is a lot faster than
784
subprocesses and generates the same logging output as running it in a
785
subprocess (which invoking the method directly does not).
787
3. Only test the one command in a single test script. Use the bzrlib
788
library when setting up tests and when evaluating the side-effects of
789
the command. We do this so that the library api has continual pressure
790
on it to be as functional as the command line in a simple manner, and
791
to isolate knock-on effects throughout the blackbox test suite when a
792
command changes its name or signature. Ideally only the tests for a
793
given command are affected when a given command is changed.
795
4. If you have a test which does actually require running bzr in a
796
subprocess you can use ``run_bzr_subprocess``. By default the spawned
797
process will not load plugins unless ``--allow-plugins`` is supplied.
803
We have a rich collection of tools to support writing tests. Please use
804
them in preference to ad-hoc solutions as they provide portability and
805
performance benefits.
810
The ``TreeBuilder`` interface allows the construction of arbitrary trees
811
with a declarative interface. A sample session might look like::
813
tree = self.make_branch_and_tree('path')
814
builder = TreeBuilder()
815
builder.start_tree(tree)
816
builder.build(['foo', "bar/", "bar/file"])
817
tree.commit('commit the tree')
818
builder.finish_tree()
820
Please see bzrlib.treebuilder for more details.
825
The ``BranchBuilder`` interface allows the creation of test branches in a
826
quick and easy manner. A sample session::
828
builder = BranchBuilder(self.get_transport().clone('relpath'))
829
builder.build_commit()
830
builder.build_commit()
831
builder.build_commit()
832
branch = builder.get_branch()
834
Please see bzrlib.branchbuilder for more details.
839
We make selective use of doctests__. In general they should provide
840
*examples* within the API documentation which can incidentally be tested. We
841
don't try to test every important case using doctests -- regular Python
842
tests are generally a better solution.
844
Most of these are in ``bzrlib/doc/api``. More additions are welcome.
846
__ http://docs.python.org/lib/module-doctest.html
851
Currently, bzr selftest is used to invoke tests.
852
You can provide a pattern argument to run a subset. For example,
853
to run just the blackbox tests, run::
855
./bzr selftest -v blackbox
857
To skip a particular test (or set of tests), use the --exclude option
858
(shorthand -x) like so::
860
./bzr selftest -v -x blackbox
862
To list tests without running them, use the --list-only option like so::
864
./bzr selftest --list-only
866
This option can be combined with other selftest options (like -x) and
867
filter patterns to understand their effect.
1066
870
Handling Errors and Exceptions
1067
871
==============================
1434
1169
http://bazaar-vcs.org/BzrWin32Installer
1437
Core Developer Tasks
1438
####################
1443
What is a Core Developer?
1444
-------------------------
1446
While everyone in the Bazaar community is welcome and encouraged to
1447
propose and submit changes, a smaller team is reponsible for pulling those
1448
changes together into a cohesive whole. In addition to the general developer
1449
stuff covered above, "core" developers have responsibility for:
1452
* reviewing blueprints
1454
* managing releases (see `Releasing Bazaar <http://doc.bazaar-vcs.org/developers/releasing.html>`_)
1457
Removing barriers to community participation is a key reason for adopting
1458
distributed VCS technology. While DVCS removes many technical barriers,
1459
a small number of social barriers are often necessary instead.
1460
By documenting how the above things are done, we hope to
1461
encourage more people to participate in these activities, keeping the
1462
differences between core and non-core contributors to a minimum.
1465
Communicating and Coordinating
1466
------------------------------
1468
While it has many advantages, one of the challenges of distributed
1469
development is keeping everyone else aware of what you're working on.
1470
There are numerous ways to do this:
1472
#. Assign bugs to yourself in Launchpad
1473
#. Mention it on the mailing list
1474
#. Mention it on IRC
1476
As well as the email notifcations that occur when merge requests are sent
1477
and reviewed, you can keep others informed of where you're spending your
1478
energy by emailing the **bazaar-commits** list implicitly. To do this,
1479
install and configure the Email plugin. One way to do this is add these
1480
configuration settings to your central configuration file (e.g.
1481
``~/.bazaar/bazaar.conf`` on Linux)::
1484
email = Joe Smith <joe.smith@internode.on.net>
1485
smtp_server = mail.internode.on.net:25
1487
Then add these lines for the relevant branches in ``locations.conf``::
1489
post_commit_to = bazaar-commits@lists.canonical.com
1490
post_commit_mailer = smtplib
1492
While attending a sprint, RobertCollins' Dbus plugin is useful for the
1493
same reason. See the documentation within the plugin for information on
1494
how to set it up and configure it.
1503
Of the many workflows supported by Bazaar, the one adopted for Bazaar
1504
development itself is known as "Decentralized with automatic gatekeeper".
1505
To repeat the explanation of this given on
1506
http://bazaar-vcs.org/Workflows:
1509
In this workflow, each developer has their own branch or
1510
branches, plus read-only access to the mainline. A software gatekeeper
1511
(e.g. PQM) has commit rights to the main branch. When a developer wants
1512
their work merged, they request the gatekeeper to merge it. The gatekeeper
1513
does a merge, a compile, and runs the test suite. If the code passes, it
1514
is merged into the mainline.
1516
In a nutshell, here's the overall submission process:
1518
#. get your work ready (including review except for trivial changes)
1519
#. push to a public location
1520
#. ask PQM to merge from that location
1523
At present, PQM always takes the changes to merge from a branch
1524
at a URL that can be read by it. For Bazaar, that means a public,
1525
typically http, URL.
1527
As a result, the following things are needed to use PQM for submissions:
1529
#. A publicly available web server
1530
#. Your OpenPGP key registered with PQM (contact RobertCollins for this)
1531
#. The PQM plugin installed and configured (not strictly required but
1532
highly recommended).
1535
Selecting a Public Branch Location
1536
----------------------------------
1538
If you don't have your own web server running, branches can always be
1539
pushed to Launchpad. Here's the process for doing that:
1541
Depending on your location throughout the world and the size of your
1542
repository though, it is often quicker to use an alternative public
1543
location to Launchpad, particularly if you can set up your own repo and
1544
push into that. By using an existing repo, push only needs to send the
1545
changes, instead of the complete repository every time. Note that it is
1546
easy to register branches in other locations with Launchpad so no benefits
1547
are lost by going this way.
1550
For Canonical staff, http://people.ubuntu.com/~<user>/ is one
1551
suggestion for public http branches. Contact your manager for information
1552
on accessing this system if required.
1554
It should also be noted that best practice in this area is subject to
1555
change as things evolve. For example, once the Bazaar smart server on
1556
Launchpad supports server-side branching, the performance situation will
1557
be very different to what it is now (Jun 2007).
1560
Configuring the PQM Plug-In
1561
---------------------------
1563
While not strictly required, the PQM plugin automates a few things and
1564
reduces the chance of error. Before looking at the plugin, it helps to
1565
understand a little more how PQM operates. Basically, PQM requires an
1566
email indicating what you want it to do. The email typically looks like
1569
star-merge source-branch target-branch
1573
star-merge http://bzr.arbash-meinel.com/branches/bzr/jam-integration http://bazaar-vcs.org/bzr/bzr.dev
1575
Note that the command needs to be on one line. The subject of the email
1576
will be used for the commit message. The email also needs to be ``gpg``
1577
signed with a key that PQM accepts.
1579
The advantages of using the PQM plugin are:
1581
#. You can use the config policies to make it easy to set up public
1582
branches, so you don't have to ever type the full paths you want to merge
1585
#. It checks to make sure the public branch last revision matches the
1586
local last revision so you are submitting what you think you are.
1588
#. It uses the same public_branch and smtp sending settings as bzr-email,
1589
so if you have one set up, you have the other mostly set up.
1591
#. Thunderbird refuses to not wrap lines, and request lines are usually
1592
pretty long (you have 2 long URLs in there).
1594
Here are sample configuration settings for the PQM plugin. Here are the
1595
lines in bazaar.conf::
1598
email = Joe Smith <joe.smith@internode.on.net>
1599
smtp_server=mail.internode.on.net:25
1601
And here are the lines in ``locations.conf`` (or ``branch.conf`` for
1602
dirstate-tags branches)::
1604
[/home/joe/bzr/my-integration]
1605
push_location = sftp://joe-smith@bazaar.launchpad.net/%7Ejoe-smith/bzr/my-integration/
1606
push_location:policy = norecurse
1607
public_branch = http://bazaar.launchpad.net/~joe-smith/bzr/my-integration/
1608
public_branch:policy = appendpath
1609
pqm_email = Bazaar PQM <pqm@bazaar-vcs.org>
1610
pqm_branch = http://bazaar-vcs.org/bzr/bzr.dev
1612
Note that the push settings will be added by the first ``push`` on
1613
a branch. Indeed the preferred way to generate the lines above is to use
1614
``push`` with an argument, then copy-and-paste the other lines into
1621
Here is one possible recipe once the above environment is set up:
1623
#. pull bzr.dev => my-integration
1624
#. merge patch => my-integration
1625
#. fix up any final merge conflicts (NEWS being the big killer here).
1631
The ``push`` step is not required if ``my-integration`` is a checkout of
1634
Because of defaults, you can type a single message into commit and
1635
pqm-commit will reuse that.
1638
Tracking Change Acceptance
1639
--------------------------
1641
The web interface to PQM is https://pqm.bazaar-vcs.org/. After submitting
1642
a change, you can visit this URL to confirm it was received and placed in
1645
When PQM completes processing a change, an email is sent to you with the
1649
Reviewing Blueprints
1650
====================
1652
Blueprint Tracking Using Launchpad
1653
----------------------------------
1655
New features typically require a fair amount of discussion, design and
1656
debate. For Bazaar, that information is often captured in a so-called
1657
"blueprint" on our Wiki. Overall tracking of blueprints and their status
1658
is done using Launchpad's relevant tracker,
1659
https://blueprints.launchpad.net/bzr/. Once a blueprint for ready for
1660
review, please announce it on the mailing list.
1662
Alternatively, send an email beginning with [RFC] with the proposal to the
1663
list. In some cases, you may wish to attach proposed code or a proposed
1664
developer document if that best communicates the idea. Debate can then
1665
proceed using the normal merge review processes.
1668
Recording Blueprint Review Feedback
1669
-----------------------------------
1671
Unlike its Bug Tracker, Launchpad's Blueprint Tracker doesn't currently
1672
(Jun 2007) support a chronological list of comment responses. Review
1673
feedback can either be recorded on the Wiki hosting the blueprints or by
1674
using Launchpad's whiteboard feature.
1681
Using Releases and Milestones in Launchpad
1682
------------------------------------------
1684
TODO ... (Exact policies still under discussion)
1690
Keeping on top of bugs reported is an important part of ongoing release
1691
planning. Everyone in the community is welcome and encouraged to raise
1692
bugs, confirm bugs raised by others, and nominate a priority. Practically
1693
though, a good percentage of bug triage is often done by the core
1694
developers, partially because of their depth of product knowledge.
1696
With respect to bug triage, core developers are encouraged to play an
1697
active role with particular attention to the following tasks:
1699
* keeping the number of unconfirmed bugs low
1700
* ensuring the priorities are generally right (everything as critical - or
1701
medium - is meaningless)
1702
* looking out for regressions and turning those around sooner rather than later.
1705
As well as prioritizing bugs and nominating them against a
1706
target milestone, Launchpad lets core developers offer to mentor others in
1711
1173
vim: ft=rst tw=74 ai