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 |
||
6082.2.1
by Vincent Ladeuil
Implement default values from environment for config options |
9 |
* a value: a unicode string or a list of unicode strings. |
5743.12.10
by Vincent Ladeuil
Add documentation. |
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 |
||
6082.2.1
by Vincent Ladeuil
Implement default values from environment for config options |
22 |
* default_from_env: a list of environment variables. The first variable set |
23 |
will provide a default value overriding 'default' which remains the |
|
6082.2.2
by Vincent Ladeuil
Fix typos. |
24 |
default value if *no* environment variable is set. |
6082.2.1
by Vincent Ladeuil
Implement default values from environment for config options |
25 |
|
6056.2.4
by Vincent Ladeuil
Option help is now part of the object itself. |
26 |
* help: a doc string describing the option, the first line should be a |
27 |
summary and can be followed by a blank line and a more detailed |
|
28 |
explanation. |
|
5743.3.7
by Vincent Ladeuil
Add some documentation about option and sections. |
29 |
|
6059.1.1
by Vincent Ladeuil
Implement from_unicode to convert config option values from store. |
30 |
* from_unicode: a callable accepting a unicode string and returning a |
31 |
suitable value for the option. If the string cannot be coerced it should |
|
32 |
return None. |
|
33 |
||
6059.1.5
by Vincent Ladeuil
Handle invalid config option values. |
34 |
* invalid: the action to be taken when an invalid value is encountered in a |
35 |
store (during a Stack.get()). |
|
36 |
||
5743.3.7
by Vincent Ladeuil
Add some documentation about option and sections. |
37 |
Sections |
38 |
-------- |
|
39 |
||
40 |
Options are grouped into sections which share some properties with the well |
|
41 |
known dict objects: |
|
42 |
||
5743.12.10
by Vincent Ladeuil
Add documentation. |
43 |
* the key is the name, |
44 |
* you can get, set and remove an option, |
|
45 |
* the value is a unicode string. |
|
5743.3.7
by Vincent Ladeuil
Add some documentation about option and sections. |
46 |
|
5743.3.10
by Vincent Ladeuil
Fix typos mentioned in reviews. |
47 |
MutableSection is needed to set or remove an option, ReadOnlySection should |
5743.3.7
by Vincent Ladeuil
Add some documentation about option and sections. |
48 |
be used otherwise. |
49 |
||
6082.5.24
by Vincent Ladeuil
More documentation about local section options. |
50 |
|
5743.4.16
by Vincent Ladeuil
Some doc for the stores. |
51 |
Stores |
52 |
------ |
|
53 |
||
5743.4.25
by Vincent Ladeuil
Address review comments by jelmer and poolie. |
54 |
Options can be persistent in which case they are saved into Stores. |
5743.4.16
by Vincent Ladeuil
Some doc for the stores. |
55 |
|
56 |
``config.Store`` defines the abstract interface that all stores should |
|
57 |
implement. |
|
58 |
||
5743.4.25
by Vincent Ladeuil
Address review comments by jelmer and poolie. |
59 |
This object doesn't provide direct access to the options, it only provides |
60 |
access to Sections. This is deliberate to ensure that sections can be |
|
61 |
properly shared by reusing the same underlying objects. Accessing options |
|
62 |
should be done via the ``Section`` objects. |
|
5743.4.16
by Vincent Ladeuil
Some doc for the stores. |
63 |
|
64 |
A ``Store`` can contain one or more sections, each section is uniquely |
|
65 |
identified by a unicode string. |
|
66 |
||
67 |
``config.ConfigObjStore`` is an implementation that use ``ConfigObj``. |
|
68 |
||
69 |
Depending on the object it is associated with (or not) a ``Store`` also needs |
|
70 |
to implement a locking mechanism. ``LockableConfigObjStore`` implements such a |
|
71 |
mechanism for ``ConfigObj`` based stores. |
|
5743.5.6
by Vincent Ladeuil
Mention that the test framework ought to support adding new stores. |
72 |
|
73 |
Classes are provided for the usual Bazaar configuration files and could be |
|
74 |
used as examples to define new ones if needed. The associated tests provides a |
|
75 |
basis for new classes which only need to register themselves in the right |
|
76 |
places to inherit from the existing basic tests and add their own specific |
|
77 |
ones. |
|
5743.2.29
by Vincent Ladeuil
Add doc for the section matchers. |
78 |
|
79 |
Filtering sections |
|
80 |
------------------ |
|
81 |
||
82 |
For some contexts, only some sections from a given store will apply. Defining |
|
6082.5.24
by Vincent Ladeuil
More documentation about local section options. |
83 |
which is what the ``SectionMatcher`` objects are about. |
5743.2.29
by Vincent Ladeuil
Add doc for the section matchers. |
84 |
|
85 |
The main constraint here is that a ``SectionMatcher`` should delay the loading |
|
86 |
of the associated store as long as possible. The constructor should collect |
|
87 |
all data needed for the selection and uses it while processing the sections in |
|
88 |
``get_sections``. |
|
89 |
||
6123.7.1
by Vincent Ladeuil
Provide config.IdMatcher for config files defining secion names as unique ids |
90 |
Only ``ReadOnlySection`` objects are manipulated here but a |
91 |
``SectionMatcher`` can return dedicated ``Section`` objects to provide |
|
92 |
additional context (the ``LocationSection`` add an ``extra_path`` attribute |
|
93 |
to implement the ``appendpath`` policy for example). If no sections match, |
|
94 |
an empty list is returned. |
|
5743.2.29
by Vincent Ladeuil
Add doc for the section matchers. |
95 |
|
6082.5.24
by Vincent Ladeuil
More documentation about local section options. |
96 |
Options local to a section can also be defined for special purposes and be |
97 |
handled by ``Section.get()``. One such option is ``relpath`` which is |
|
98 |
defined in ``LocationSection`` as an alternative to the ``appendpath`` |
|
99 |
policy. |
|
100 |
||
101 |
For ``appendpath``, the ``LocationSection`` will carry ``extra_path`` as |
|
102 |
``832013-expand-in-stack`` and ``relpath`` will be available as a |
|
103 |
``Section`` local option with the same value. Note that such options can |
|
104 |
only be expanded inside the section that defines them. |
|
5743.1.24
by Vincent Ladeuil
Some generic doc about stacks. |
105 |
|
6123.7.1
by Vincent Ladeuil
Provide config.IdMatcher for config files defining secion names as unique ids |
106 |
Specific section matchers can be implemented by overriding ``get_sections`` |
107 |
or just ``match``. |
|
108 |
||
109 |
``bzrlib`` provides: |
|
110 |
||
111 |
* ``LocationMatcher(store, location)``: To select all sections that match |
|
112 |
``location``. |
|
113 |
||
6123.7.2
by Vincent Ladeuil
Rename IdMatcher to NameMatcher. |
114 |
* ``NameMatcher(store, unique_id)``: To select a single section matching |
6123.7.1
by Vincent Ladeuil
Provide config.IdMatcher for config files defining secion names as unique ids |
115 |
``unique_id``. |
116 |
||
5743.1.24
by Vincent Ladeuil
Some generic doc about stacks. |
117 |
Stacks |
118 |
------ |
|
119 |
||
120 |
An option can take different values depending on the context it is used. Such |
|
121 |
a context can involve configuration files, options from the command line, |
|
122 |
default values in bzrlib and then some. |
|
123 |
||
124 |
Such a context is implemented by creating a list of ``Section`` stacked upon |
|
125 |
each other. A ``Stack`` can then be asked for an option value and returns the |
|
126 |
first definition found. |
|
127 |
||
128 |
This provides a great flexibility to decide priorities between sections when |
|
129 |
the stack is defined without to worry about them in the code itself. |
|
130 |
||
131 |
A stack also defines a mutable section (which can be None) to handle |
|
132 |
modifications. |
|
133 |
||
134 |
Many sections (or even stores) are aimed at providing default values for an |
|
135 |
option but these sections shouldn't be modified lightly as modifying an option |
|
136 |
used for different contexts will indeed be seen by all these contexts. |
|
137 |
||
5743.1.35
by Vincent Ladeuil
Address some review comments from jelmer and poolie. |
138 |
Default values in configuration files are defined by users. Developers |
5743.1.24
by Vincent Ladeuil
Some generic doc about stacks. |
139 |
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. |
140 |
to find which section (or sections) should be modified. |
5743.1.24
by Vincent Ladeuil
Some generic doc about stacks. |
141 |
|
5743.1.35
by Vincent Ladeuil
Address some review comments from jelmer and poolie. |
142 |
A ``Stack`` defines a mutable section when there is no ambiguity. If there |
143 |
is one, then the *user* should be able to decide and in this case a new |
|
144 |
``Stack`` can be created cheaply. |
|
5743.1.24
by Vincent Ladeuil
Some generic doc about stacks. |
145 |
|
5743.6.5
by Vincent Ladeuil
Complement the stacks doc. |
146 |
Different stacks can be created for different purposes, the existing |
5743.6.16
by Vincent Ladeuil
Fix typo. |
147 |
``GlobalStack``, ``LocationStack`` and ``BranchStack`` can be used as basis |
5743.6.5
by Vincent Ladeuil
Complement the stacks doc. |
148 |
or examples. These classes are the only ones that should be used in code, |
149 |
``Stores`` can be used to build them but shouldn't be used otherwise, ditto |
|
150 |
for sections. Again, the associated tests could and should be used against the |
|
151 |
created stacks. |