tiramisu/doc/configapi.txt

100 lines
3.8 KiB
Text
Raw Normal View History

.. default-role:: literal
Config API Details
==================
:module: :api:`config.py`
:test cases: - :api:`test_config_api.py`
- :api:`test_config_big_example.py`
2012-10-05 16:00:07 +02:00
The handling of options is split into two parts: the description of
which options are available, what their possible values and defaults are
and how they are organized into a tree. A specific choice of options is
bundled into a configuration object which has a reference to its option
description (and therefore makes sure that the configuration values
adhere to the option description).
The configuration object
-------------------------
2012-10-05 16:00:07 +02:00
:api:`config.Config()` object that lives in :api:`config.py` hold the
choosen values for the options (or the default value for the
:api:`option.Option()` object, if no choice was made).
2012-10-05 16:00:07 +02:00
A `Config` object is informed by an :api:`option.OptionDescription`
instance. The attributes of the ``Config`` objects are the names of the
children of the ``OptionDescription``.
Here are the (useful) methods on ``Config``:
:api:`config.Config.__init__(self, descr, **overrides)`:
2012-10-05 16:00:07 +02:00
``descr`` is an instance of :api:`option.OptionDescription` that
describes the configuration object. ``override`` can be used to
set different default values (see method ``override``).
:api:`config.Config.set(self, **kwargs)`:
2012-10-05 16:00:07 +02:00
"do what I mean"-interface to option setting. Searches all paths
starting from that config for matches of the optional arguments
and sets the found option if the match is not ambiguous.
:api:`config.Config.get(self, name)`:
2012-10-05 16:00:07 +02:00
the behavior is much like the attribute access way, except that
the search for the option is performed recursively in the whole
configuration tree.
:api:`config.Config.cfgimpl_read_write()`:
2012-10-05 16:00:07 +02:00
configuration level `read_write` status, see :doc:`status`
:api:`config.Config.cfgimpl_read_only()`:
2012-10-05 16:00:07 +02:00
configuration level `read_only` status, see :doc:`status`
2012-10-05 16:00:07 +02:00
Here are some private attributes of a `Config()` object, for a
comprehension of the internal merchanism:
2012-10-05 16:00:07 +02:00
- `_cfgimpl_descr =` :api:`option.OptionDescription()`,
e.g. the :ref:`optionapi#schema`
2012-10-05 16:00:07 +02:00
- `_cfgimpl_values` contains the :api:`option.Option()`'s values.
Yes, the values of the options: remember that the values are stored **inside**
the :api:`config.Config()` and not in the `Option()`
2012-10-05 16:00:07 +02:00
`_cfgimpl_values` contains something like that
::
{'int': 0, 'wantframework': False, 'objspace': 'std', 'bool': False,
'str': 'abc', 'gc': <config.Config object at 0xa33f8ec>, 'wantref': False}
2012-10-05 16:00:07 +02:00
We can see that values can also be config objects, it's the
sub-namespaces that are stored in the values as `Config()` objects.
convenience utilities (iteration, exports...)
-----------------------------------------------
2012-10-05 16:00:07 +02:00
With this :api:`config.Config()` configuration management entry point,
it is possible to
2012-10-05 16:00:07 +02:00
- `iter` on config, notice that there is an iteration order wich is
the order of the :ref:`optionapi#schema` specification entries,
- compare two configs (equality),
- export the whole config into a `dict` with :api:`config.make_dict()`,
2012-11-14 11:30:11 +01:00
2012-10-05 16:00:07 +02:00
.. - `validate()` an option value into a config, see :doc:`consistency`.
2012-10-05 16:00:07 +02:00
:api:`option.Option()` objects in a config are iterable in the pythonic
way, that is something like `[(name, value) for name, value in config]`.
To iter on groups in the same manner, use the
:api:`config.Config.iter_groups()` method wich yields generators too.
**iteration utilities**
2012-10-05 16:00:07 +02:00
:api:`config.Config.__iter__()`
Pythonesque way of parsing group's ordered options.
2012-10-05 16:00:07 +02:00
:api:`config.Config.iter_groups(group_type=None)`:
2012-10-05 16:00:07 +02:00
To iter on groups objects only.
All groups are returned if `group_type` is `None`, otherwise the groups
can be filtered by categories (families, or whatever).