~bzr-pqm/bzr/bzr.dev

5743.3.7 by Vincent Ladeuil
Add some documentation about option and sections.
1
Configuring Bazaar
2
==================
3
4
A configuration option has:
5
5743.12.10 by Vincent Ladeuil
Add documentation.
6
* a name: a valid python identifier (even if it's not used as an
5743.3.7 by Vincent Ladeuil
Add some documentation about option and sections.
7
  identifier in python itself)
8
5743.12.10 by Vincent Ladeuil
Add documentation.
9
* a value: a unicode string
10
11
Option
12
------
13
14
The Option object is used to define its properties:
15
16
* name: a name: a valid python identifier (even if it's not used as an
17
  identifier in python itself). This is also used to register the option.
18
19
* default: the default value that Stack.get() should return if no
20
  value can be found for the option.
21
6056.2.4 by Vincent Ladeuil
Option help is now part of the object itself.
22
* help: a doc string describing the option, the first line should be a
23
  summary and can be followed by a blank line and a more detailed
24
  explanation.
5743.3.7 by Vincent Ladeuil
Add some documentation about option and sections.
25
6059.1.1 by Vincent Ladeuil
Implement from_unicode to convert config option values from store.
26
* from_unicode: a callable accepting a unicode string and returning a
27
  suitable value for the option. If the string cannot be coerced it should
28
  return None.
29
5743.3.7 by Vincent Ladeuil
Add some documentation about option and sections.
30
Sections
31
--------
32
33
Options are grouped into sections which share some properties with the well
34
known dict objects:
35
5743.12.10 by Vincent Ladeuil
Add documentation.
36
* the key is the name,
37
* you can get, set and remove an option,
38
* the value is a unicode string.
5743.3.7 by Vincent Ladeuil
Add some documentation about option and sections.
39
5743.3.10 by Vincent Ladeuil
Fix typos mentioned in reviews.
40
MutableSection is needed to set or remove an option, ReadOnlySection should
5743.3.7 by Vincent Ladeuil
Add some documentation about option and sections.
41
be used otherwise.
42
5743.4.16 by Vincent Ladeuil
Some doc for the stores.
43
Stores
44
------
45
5743.4.25 by Vincent Ladeuil
Address review comments by jelmer and poolie.
46
Options can be persistent in which case they are saved into Stores.
5743.4.16 by Vincent Ladeuil
Some doc for the stores.
47
48
``config.Store`` defines the abstract interface that all stores should
49
implement.
50
5743.4.25 by Vincent Ladeuil
Address review comments by jelmer and poolie.
51
This object doesn't provide direct access to the options, it only provides
52
access to Sections. This is deliberate to ensure that sections can be
53
properly shared by reusing the same underlying objects. Accessing options
54
should be done via the ``Section`` objects.
5743.4.16 by Vincent Ladeuil
Some doc for the stores.
55
56
A ``Store`` can contain one or more sections, each section is uniquely
57
identified by a unicode string.
58
59
``config.ConfigObjStore`` is an implementation that use ``ConfigObj``.
60
61
Depending on the object it is associated with (or not) a ``Store`` also needs
62
to implement a locking mechanism. ``LockableConfigObjStore`` implements such a
63
mechanism for ``ConfigObj`` based stores.
5743.5.6 by Vincent Ladeuil
Mention that the test framework ought to support adding new stores.
64
65
Classes are provided for the usual Bazaar configuration files and could be
66
used as examples to define new ones if needed. The associated tests provides a
67
basis for new classes which only need to register themselves in the right
68
places to inherit from the existing basic tests and add their own specific
69
ones.
5743.2.29 by Vincent Ladeuil
Add doc for the section matchers.
70
71
Filtering sections
72
------------------
73
74
For some contexts, only some sections from a given store will apply. Defining
75
which is what the ``SectionMatcher`` are about.
76
77
The main constraint here is that a ``SectionMatcher`` should delay the loading
78
of the associated store as long as possible. The constructor should collect
79
all data needed for the selection and uses it while processing the sections in
80
``get_sections``.
81
82
Only ``ReadOnlySection`` objects are manipulated here but a ``SectionMatcher``
83
can return dedicated ``Section`` to provide additional context (the
84
``LocationSection`` add an ``extra_path`` attribute to implement the
85
``appendpath`` policy for example).
86
87
.. FIXME: Replace the appendpath example if/when it's deprecated ;)
5743.1.24 by Vincent Ladeuil
Some generic doc about stacks.
88
89
Stacks
90
------
91
92
An option can take different values depending on the context it is used. Such
93
a context can involve configuration files, options from the command line,
94
default values in bzrlib and then some.
95
96
Such a context is implemented by creating a list of ``Section`` stacked upon
97
each other. A ``Stack`` can then be asked for an option value and returns the
98
first definition found.
99
100
This provides a great flexibility to decide priorities between sections when
101
the stack is defined without to worry about them in the code itself.
102
103
A stack also defines a mutable section (which can be None) to handle
104
modifications.
105
106
Many sections (or even stores) are aimed at providing default values for an
107
option but these sections shouldn't be modified lightly as modifying an option
108
used for different contexts will indeed be seen by all these contexts.
109
5743.1.35 by Vincent Ladeuil
Address some review comments from jelmer and poolie.
110
Default values in configuration files are defined by users. Developers
5743.1.24 by Vincent Ladeuil
Some generic doc about stacks.
111
shouldn't have to modify them, as such, no mechanism nor heuristics are used
5743.1.35 by Vincent Ladeuil
Address some review comments from jelmer and poolie.
112
to find which section (or sections) should be modified.
5743.1.24 by Vincent Ladeuil
Some generic doc about stacks.
113
5743.1.35 by Vincent Ladeuil
Address some review comments from jelmer and poolie.
114
A ``Stack`` defines a mutable section when there is no ambiguity.  If there
115
is one, then the *user* should be able to decide and in this case a new
116
``Stack`` can be created cheaply.
5743.1.24 by Vincent Ladeuil
Some generic doc about stacks.
117
5743.6.5 by Vincent Ladeuil
Complement the stacks doc.
118
Different stacks can be created for different purposes, the existing
5743.6.16 by Vincent Ladeuil
Fix typo.
119
``GlobalStack``, ``LocationStack`` and ``BranchStack`` can be used as basis
5743.6.5 by Vincent Ladeuil
Complement the stacks doc.
120
or examples. These classes are the only ones that should be used in code,
121
``Stores`` can be used to build them but shouldn't be used otherwise, ditto
122
for sections. Again, the associated tests could and should be used against the
123
created stacks.