~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to doc/developers/configuration.txt

  • Committer: Benji York
  • Date: 2011-08-19 18:02:37 UTC
  • mto: This revision was merged to the branch mainline in revision 6101.
  • Revision ID: benji@benjiyork.com-20110819180237-2n0sdcfs5v7bxksi
fix bug 702914

Show diffs side-by-side

added added

removed removed

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