220
203
Navigating the Code Base
221
204
========================
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.
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.
376
Essential Domain Classes
377
########################
379
Introducing the Object Model
380
============================
382
The core domain objects within the bazaar model are:
392
Transports are explained below. See http://bazaar-vcs.org/Classes/
393
for an introduction to the other key classes.
398
The ``Transport`` layer handles access to local or remote directories.
399
Each Transport object acts like a logical connection to a particular
400
directory, and it allows various operations on files within it. You can
401
*clone* a transport to get a new Transport connected to a subdirectory or
404
Transports are not used for access to the working tree. At present
405
working trees are always local and they are accessed through the regular
406
Python file io mechanisms.
440
409
-----------------
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
--------------------------
457
If you'd like to propose a change, please post to the
458
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
460
can pick it out, and explain the change in the email message text.
461
Remember to update the NEWS file as part of your change if it makes any
462
changes visible to users or plugin developers. Please include a diff
463
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.
474
Please do **NOT** put [PATCH] or [MERGE] in the subject line if you don't
475
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
487
:approve: Reviewer wants this submission merged.
488
:tweak: Reviewer wants this submission merged with small changes. (No
490
:abstain: Reviewer does not intend to vote on this patch.
491
:resubmit: Please make changes and resubmit for review.
492
:reject: Reviewer doesn't want this kind of change merged.
493
:comment: Not really a vote. Reviewer just wants to comment, for now.
495
If a change gets two approvals from core reviewers, and no rejections,
496
then it's OK to come in. Any of the core developers can bring it into the
497
bzr.dev trunk and backport it to maintenance branches if required. The
498
Release Manager will merge the change into the branch for a pending
499
release, if any. As a guideline, core developers usually merge their own
500
changes and volunteer to merge other contributions if they were the second
501
reviewer to agree to a change.
503
To track the progress of proposed changes, use Bundle Buggy. See
504
http://bundlebuggy.aaronbentley.com/help for a link to all the
505
outstanding merge requests together with an explanation of the columns.
506
Bundle Buggy will also mail you a link to track just your change.
411
Transports work in URLs. Take note that URLs are by definition only
412
ASCII - the decision of how to encode a Unicode string into a URL must be
413
taken at a higher level, typically in the Store. (Note that Stores also
414
escape filenames which cannot be safely stored on all filesystems, but
415
this is a different level.)
417
The main reason for this is that it's not possible to safely roundtrip a
418
URL into Unicode and then back into the same URL. The URL standard
419
gives a way to represent non-ASCII bytes in ASCII (as %-escapes), but
420
doesn't say how those bytes represent non-ASCII characters. (They're not
421
guaranteed to be UTF-8 -- that is common but doesn't happen everywhere.)
423
For example if the user enters the url ``http://example/%e0`` there's no
424
way to tell whether that character represents "latin small letter a with
425
grave" in iso-8859-1, or "latin small letter r with acute" in iso-8859-2
426
or malformed UTF-8. So we can't convert their URL to Unicode reliably.
428
Equally problematic if we're given a url-like string containing non-ascii
429
characters (such as the accented a) we can't be sure how to convert that
430
to the correct URL, because we don't know what encoding the server expects
431
for those characters. (Although this is not totally reliable we might still
432
accept these and assume they should be put into UTF-8.)
434
A similar edge case is that the url ``http://foo/sweet%2Fsour`` contains
435
one directory component whose name is "sweet/sour". The escaped slash is
436
not a directory separator. If we try to convert URLs to regular Unicode
437
paths this information will be lost.
439
This implies that Transports must natively deal with URLs; for simplicity
440
they *only* deal with URLs and conversion of other strings to URLs is done
441
elsewhere. Information they return, such as from ``list_dir``, is also in
442
the form of URL components.
451
We have a commitment to 6 months API stability - any supported symbol in a
452
release of bzr MUST NOT be altered in any way that would result in
453
breaking existing code that uses it. That means that method names,
454
parameter ordering, parameter names, variable and attribute names etc must
455
not be changed without leaving a 'deprecated forwarder' behind. This even
456
applies to modules and classes.
458
If you wish to change the behaviour of a supported API in an incompatible
459
way, you need to change its name as well. For instance, if I add an optional keyword
460
parameter to branch.commit - that's fine. On the other hand, if I add a
461
keyword parameter to branch.commit which is a *required* transaction
462
object, I should rename the API - i.e. to 'branch.commit_transaction'.
464
When renaming such supported API's, be sure to leave a deprecated_method (or
465
_function or ...) behind which forwards to the new API. See the
466
bzrlib.symbol_versioning module for decorators that take care of the
467
details for you - such as updating the docstring, and issuing a warning
468
when the old api is used.
470
For unsupported API's, it does not hurt to follow this discipline, but it's
471
not required. Minimally though, please try to rename things so that
472
callers will at least get an AttributeError rather than weird results.
508
475
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
476
=======================
478
Please write PEP-8__ compliant code.
527
480
One often-missed requirement is that the first line of docstrings
528
481
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
483
__ http://www.python.org/peps/pep-0008.html
619
489
* Imports should be done at the top-level of the file, unless there is
620
490
a strong reason to have them lazily loaded when a particular
796
633
variable, so some bugs are not detected right away.
802
The null revision is the ancestor of all revisions. Its revno is 0, its
803
revision-id is ``null:``, and its tree is the empty tree. When referring
804
to the null revision, please use ``bzrlib.revision.NULL_REVISION``. Old
805
code sometimes uses ``None`` for the null revision, but this practice is
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
987
693
should be only in the command-line tool.
990
Progress and Activity Indications
991
---------------------------------
993
bzrlib has a way for code to display to the user that stuff is happening
994
during a long operation. There are two particular types: *activity* which
995
means that IO is happening on a Transport, and *progress* which means that
996
higher-level application work is occurring. Both are drawn together by
999
Transport objects are responsible for calling `report_transport_activity`
1002
Progress uses a model/view pattern: application code acts on a
1003
`ProgressTask` object, which notifies the UI when it needs to be
1004
displayed. Progress tasks form a stack. To create a new progress task on
1005
top of the stack, call `bzrlib.ui.ui_factory.nested_progress_bar()`, then
1006
call `update()` on the returned ProgressTask. It can be updated with just
1007
a text description, with a numeric count, or with a numeric count and
1008
expected total count. If an expected total count is provided the view
1009
can show the progress moving along towards the expected total.
1011
The user should call `finish` on the `ProgressTask` when the logical
1012
operation has finished, so it can be removed from the stack.
1014
Progress tasks have a complex relationship with generators: it's a very
1015
good place to use them, but because python2.4 does not allow ``finally``
1016
blocks in generators it's hard to clean them up properly. In this case
1017
it's probably better to have the code calling the generator allocate a
1018
progress task for its use and then call `finalize` when it's done, which
1019
will close it if it was not already closed. The generator should also
1020
finish the progress task when it exits, because it may otherwise be a long
1021
time until the finally block runs.
1023
https://wiki.ubuntu.com/UnitsPolicy provides a good explanation about
1024
which unit should be used when. Roughly speaking, IEC standard applies
1025
for base-2 units and SI standard applies for base-10 units::
1026
* for network bandwidth an disk sizes, use base-10 (Mbits/s, kB/s, GB),
1027
* for RAM sizes, use base-2 (GiB, TiB).
1033
Bazaar has online help for various topics through ``bzr help COMMAND`` or
1034
equivalently ``bzr command -h``. We also have help on command options,
1035
and on other help topics. (See ``help_topics.py``.)
1037
As for python docstrings, the first paragraph should be a single-sentence
1038
synopsis of the command.
1040
The help for options should be one or more proper sentences, starting with
1041
a capital letter and finishing with a full stop (period).
1043
All help messages and documentation should have two spaces between
699
In general tests should be placed in a file named test_FOO.py where
700
FOO is the logical thing under test. That file should be placed in the
701
tests subdirectory under the package being tested.
703
For example, tests for merge3 in bzrlib belong in bzrlib/tests/test_merge3.py.
704
See bzrlib/tests/test_sampler.py for a template test script.
706
Tests can be written for the UI or for individual areas of the library.
707
Choose whichever is appropriate: if adding a new command, or a new command
708
option, then you should be writing a UI test. If you are both adding UI
709
functionality and library functionality, you will want to write tests for
710
both the UI and the core behaviours. We call UI tests 'blackbox' tests
711
and they are found in ``bzrlib/tests/blackbox/*.py``.
713
When writing blackbox tests please honour the following conventions:
715
1. Place the tests for the command 'name' in
716
bzrlib/tests/blackbox/test_name.py. This makes it easy for developers
717
to locate the test script for a faulty command.
719
2. Use the 'self.run_bzr("name")' utility function to invoke the command
720
rather than running bzr in a subprocess or invoking the
721
cmd_object.run() method directly. This is a lot faster than
722
subprocesses and generates the same logging output as running it in a
723
subprocess (which invoking the method directly does not).
725
3. Only test the one command in a single test script. Use the bzrlib
726
library when setting up tests and when evaluating the side-effects of
727
the command. We do this so that the library api has continual pressure
728
on it to be as functional as the command line in a simple manner, and
729
to isolate knock-on effects throughout the blackbox test suite when a
730
command changes its name or signature. Ideally only the tests for a
731
given command are affected when a given command is changed.
733
4. If you have a test which does actually require running bzr in a
734
subprocess you can use ``run_bzr_subprocess``. By default the spawned
735
process will not load plugins unless ``--allow-plugins`` is supplied.
741
We have a rich collection of tools to support writing tests. Please use
742
them in preference to ad-hoc solutions as they provide portability and
743
performance benefits.
748
The ``TreeBuilder`` interface allows the construction of arbitrary trees
749
with a declarative interface. A sample session might look like::
751
tree = self.make_branch_and_tree('path')
752
builder = TreeBuilder()
753
builder.start_tree(tree)
754
builder.build(['foo', "bar/", "bar/file"])
755
tree.commit('commit the tree')
756
builder.finish_tree()
758
Please see bzrlib.treebuilder for more details.
763
The ``BranchBuilder`` interface allows the creation of test branches in a
764
quick and easy manner. A sample session::
766
builder = BranchBuilder(self.get_transport().clone('relpath'))
767
builder.build_commit()
768
builder.build_commit()
769
builder.build_commit()
770
branch = builder.get_branch()
772
Please see bzrlib.branchbuilder for more details.
777
We make selective use of doctests__. In general they should provide
778
*examples* within the API documentation which can incidentally be tested. We
779
don't try to test every important case using doctests -- regular Python
780
tests are generally a better solution.
782
Most of these are in ``bzrlib/doc/api``. More additions are welcome.
784
__ http://docs.python.org/lib/module-doctest.html
789
Currently, bzr selftest is used to invoke tests.
790
You can provide a pattern argument to run a subset. For example,
791
to run just the blackbox tests, run::
793
./bzr selftest -v blackbox
795
To skip a particular test (or set of tests), use the --exclude option
796
(shorthand -x) like so::
798
./bzr selftest -v -x blackbox
800
To list tests without running them, use the --list-only option like so::
802
./bzr selftest --list-only
804
This option can be combined with other selftest options (like -x) and
805
filter patterns to understand their effect.
1047
808
Handling Errors and Exceptions
1415
1107
http://bazaar-vcs.org/BzrWin32Installer
1418
Core Developer Tasks
1419
####################
1424
What is a Core Developer?
1425
-------------------------
1427
While everyone in the Bazaar community is welcome and encouraged to
1428
propose and submit changes, a smaller team is reponsible for pulling those
1429
changes together into a cohesive whole. In addition to the general developer
1430
stuff covered above, "core" developers have responsibility for:
1433
* reviewing blueprints
1435
* managing releases (see `Releasing Bazaar <http://doc.bazaar-vcs.org/developers/releasing.html>`_)
1438
Removing barriers to community participation is a key reason for adopting
1439
distributed VCS technology. While DVCS removes many technical barriers,
1440
a small number of social barriers are often necessary instead.
1441
By documenting how the above things are done, we hope to
1442
encourage more people to participate in these activities, keeping the
1443
differences between core and non-core contributors to a minimum.
1446
Communicating and Coordinating
1447
------------------------------
1449
While it has many advantages, one of the challenges of distributed
1450
development is keeping everyone else aware of what you're working on.
1451
There are numerous ways to do this:
1453
#. Assign bugs to yourself in Launchpad
1454
#. Mention it on the mailing list
1455
#. Mention it on IRC
1457
As well as the email notifcations that occur when merge requests are sent
1458
and reviewed, you can keep others informed of where you're spending your
1459
energy by emailing the **bazaar-commits** list implicitly. To do this,
1460
install and configure the Email plugin. One way to do this is add these
1461
configuration settings to your central configuration file (e.g.
1462
``~/.bazaar/bazaar.conf`` on Linux)::
1465
email = Joe Smith <joe.smith@internode.on.net>
1466
smtp_server = mail.internode.on.net:25
1468
Then add these lines for the relevant branches in ``locations.conf``::
1470
post_commit_to = bazaar-commits@lists.canonical.com
1471
post_commit_mailer = smtplib
1473
While attending a sprint, RobertCollins' Dbus plugin is useful for the
1474
same reason. See the documentation within the plugin for information on
1475
how to set it up and configure it.
1484
Of the many workflows supported by Bazaar, the one adopted for Bazaar
1485
development itself is known as "Decentralized with automatic gatekeeper".
1486
To repeat the explanation of this given on
1487
http://bazaar-vcs.org/Workflows:
1490
In this workflow, each developer has their own branch or
1491
branches, plus read-only access to the mainline. A software gatekeeper
1492
(e.g. PQM) has commit rights to the main branch. When a developer wants
1493
their work merged, they request the gatekeeper to merge it. The gatekeeper
1494
does a merge, a compile, and runs the test suite. If the code passes, it
1495
is merged into the mainline.
1497
In a nutshell, here's the overall submission process:
1499
#. get your work ready (including review except for trivial changes)
1500
#. push to a public location
1501
#. ask PQM to merge from that location
1504
At present, PQM always takes the changes to merge from a branch
1505
at a URL that can be read by it. For Bazaar, that means a public,
1506
typically http, URL.
1508
As a result, the following things are needed to use PQM for submissions:
1510
#. A publicly available web server
1511
#. Your OpenPGP key registered with PQM (contact RobertCollins for this)
1512
#. The PQM plugin installed and configured (not strictly required but
1513
highly recommended).
1516
Selecting a Public Branch Location
1517
----------------------------------
1519
If you don't have your own web server running, branches can always be
1520
pushed to Launchpad. Here's the process for doing that:
1522
Depending on your location throughout the world and the size of your
1523
repository though, it is often quicker to use an alternative public
1524
location to Launchpad, particularly if you can set up your own repo and
1525
push into that. By using an existing repo, push only needs to send the
1526
changes, instead of the complete repository every time. Note that it is
1527
easy to register branches in other locations with Launchpad so no benefits
1528
are lost by going this way.
1531
For Canonical staff, http://people.ubuntu.com/~<user>/ is one
1532
suggestion for public http branches. Contact your manager for information
1533
on accessing this system if required.
1535
It should also be noted that best practice in this area is subject to
1536
change as things evolve. For example, once the Bazaar smart server on
1537
Launchpad supports server-side branching, the performance situation will
1538
be very different to what it is now (Jun 2007).
1541
Configuring the PQM Plug-In
1542
---------------------------
1544
While not strictly required, the PQM plugin automates a few things and
1545
reduces the chance of error. Before looking at the plugin, it helps to
1546
understand a little more how PQM operates. Basically, PQM requires an
1547
email indicating what you want it to do. The email typically looks like
1550
star-merge source-branch target-branch
1554
star-merge http://bzr.arbash-meinel.com/branches/bzr/jam-integration http://bazaar-vcs.org/bzr/bzr.dev
1556
Note that the command needs to be on one line. The subject of the email
1557
will be used for the commit message. The email also needs to be ``gpg``
1558
signed with a key that PQM accepts.
1560
The advantages of using the PQM plugin are:
1562
#. You can use the config policies to make it easy to set up public
1563
branches, so you don't have to ever type the full paths you want to merge
1566
#. It checks to make sure the public branch last revision matches the
1567
local last revision so you are submitting what you think you are.
1569
#. It uses the same public_branch and smtp sending settings as bzr-email,
1570
so if you have one set up, you have the other mostly set up.
1572
#. Thunderbird refuses to not wrap lines, and request lines are usually
1573
pretty long (you have 2 long URLs in there).
1575
Here are sample configuration settings for the PQM plugin. Here are the
1576
lines in bazaar.conf::
1579
email = Joe Smith <joe.smith@internode.on.net>
1580
smtp_server=mail.internode.on.net:25
1582
And here are the lines in ``locations.conf`` (or ``branch.conf`` for
1583
dirstate-tags branches)::
1585
[/home/joe/bzr/my-integration]
1586
push_location = sftp://joe-smith@bazaar.launchpad.net/%7Ejoe-smith/bzr/my-integration/
1587
push_location:policy = norecurse
1588
public_branch = http://bazaar.launchpad.net/~joe-smith/bzr/my-integration/
1589
public_branch:policy = appendpath
1590
pqm_email = Bazaar PQM <pqm@bazaar-vcs.org>
1591
pqm_branch = http://bazaar-vcs.org/bzr/bzr.dev
1593
Note that the push settings will be added by the first ``push`` on
1594
a branch. Indeed the preferred way to generate the lines above is to use
1595
``push`` with an argument, then copy-and-paste the other lines into
1602
Here is one possible recipe once the above environment is set up:
1604
#. pull bzr.dev => my-integration
1605
#. merge patch => my-integration
1606
#. fix up any final merge conflicts (NEWS being the big killer here).
1612
The ``push`` step is not required if ``my-integration`` is a checkout of
1615
Because of defaults, you can type a single message into commit and
1616
pqm-commit will reuse that.
1619
Tracking Change Acceptance
1620
--------------------------
1622
The web interface to PQM is https://pqm.bazaar-vcs.org/. After submitting
1623
a change, you can visit this URL to confirm it was received and placed in
1626
When PQM completes processing a change, an email is sent to you with the
1630
Reviewing Blueprints
1631
====================
1633
Blueprint Tracking Using Launchpad
1634
----------------------------------
1636
New features typically require a fair amount of discussion, design and
1637
debate. For Bazaar, that information is often captured in a so-called
1638
"blueprint" on our Wiki. Overall tracking of blueprints and their status
1639
is done using Launchpad's relevant tracker,
1640
https://blueprints.launchpad.net/bzr/. Once a blueprint for ready for
1641
review, please announce it on the mailing list.
1643
Alternatively, send an email beginning with [RFC] with the proposal to the
1644
list. In some cases, you may wish to attach proposed code or a proposed
1645
developer document if that best communicates the idea. Debate can then
1646
proceed using the normal merge review processes.
1649
Recording Blueprint Review Feedback
1650
-----------------------------------
1652
Unlike its Bug Tracker, Launchpad's Blueprint Tracker doesn't currently
1653
(Jun 2007) support a chronological list of comment responses. Review
1654
feedback can either be recorded on the Wiki hosting the blueprints or by
1655
using Launchpad's whiteboard feature.
1662
Using Releases and Milestones in Launchpad
1663
------------------------------------------
1665
TODO ... (Exact policies still under discussion)
1671
Keeping on top of bugs reported is an important part of ongoing release
1672
planning. Everyone in the community is welcome and encouraged to raise
1673
bugs, confirm bugs raised by others, and nominate a priority. Practically
1674
though, a good percentage of bug triage is often done by the core
1675
developers, partially because of their depth of product knowledge.
1677
With respect to bug triage, core developers are encouraged to play an
1678
active role with particular attention to the following tasks:
1680
* keeping the number of unconfirmed bugs low
1681
* ensuring the priorities are generally right (everything as critical - or
1682
medium - is meaningless)
1683
* looking out for regressions and turning those around sooner rather than later.
1686
As well as prioritizing bugs and nominating them against a
1687
target milestone, Launchpad lets core developers offer to mentor others in
1692
1111
vim: ft=rst tw=74 ai