| 1 |
.. include:: ../header.rst |
| 2 |
|
| 3 |
=========================== |
| 4 |
Docutils Runtime Settings |
| 5 |
=========================== |
| 6 |
|
| 7 |
:Author: David Goodger, Günter Milde |
| 8 |
:Contact: [email protected] |
| 9 |
:Date: $Date: 2024-08-15 10:43:38 +0200 (Do, 15. Aug 2024) $ |
| 10 |
:Revision: $Revision: 9906 $ |
| 11 |
:Copyright: This document has been placed in the public domain. |
| 12 |
|
| 13 |
.. contents:: |
| 14 |
|
| 15 |
|
| 16 |
Introduction |
| 17 |
============ |
| 18 |
|
| 19 |
Docutils runtime settings are assembled from several sources: |
| 20 |
|
| 21 |
* Settings specifications of the selected components_, |
| 22 |
* `configuration files`_ (if enabled), and |
| 23 |
* command-line options (if enabled). |
| 24 |
|
| 25 |
The individual settings are described in `Docutils Configuration`_. |
| 26 |
|
| 27 |
|
| 28 |
Settings priority |
| 29 |
================= |
| 30 |
|
| 31 |
Docutils overlays settings in the following order (later sources |
| 32 |
overwrite earlier ones): |
| 33 |
|
| 34 |
1. Defaults specified in the `settings_spec`__ and |
| 35 |
`settings_defaults`__ attributes for each component_. |
| 36 |
|
| 37 |
__ SettingsSpec.settings_spec_ |
| 38 |
__ SettingsSpec.settings_defaults_ |
| 39 |
|
| 40 |
2. Defaults specified in the `settings_default_overrides`__ attribute |
| 41 |
for each component_. |
| 42 |
|
| 43 |
__ SettingsSpec.settings_default_overrides_ |
| 44 |
|
| 45 |
3. Application defaults specified in the `settings_overrides`__ argument |
| 46 |
of the `Publisher convenience functions`_. |
| 47 |
|
| 48 |
__ publisher.html#settings-overrides |
| 49 |
|
| 50 |
4. Settings specified in `active sections`_ of the `configuration files`_ |
| 51 |
in the order described in `Configuration File Sections & Entries`_ |
| 52 |
(if enabled). |
| 53 |
|
| 54 |
5. Command line options (if enabled). |
| 55 |
|
| 56 |
Applications may opt-out of the standard settings processing providing |
| 57 |
their own set of settings. |
| 58 |
|
| 59 |
For details see the ``docutils/__init__.py``, ``docutils/core.py``, and |
| 60 |
``docutils.frontend.py`` modules and the implementation description in |
| 61 |
`Runtime Settings Processing`_. |
| 62 |
|
| 63 |
|
| 64 |
.. _SettingsSpec: |
| 65 |
|
| 66 |
SettingsSpec base class |
| 67 |
======================= |
| 68 |
|
| 69 |
.. note:: |
| 70 |
Implementation details will change with the move to replace the |
| 71 |
deprecated optparse_ module with argparse_. |
| 72 |
|
| 73 |
The `docutils.SettingsSpec` base class is inherited by Docutils |
| 74 |
components_ and `frontend.OptionParser`. It defines six attributes: |
| 75 |
|
| 76 |
attributes |
| 77 |
---------- |
| 78 |
|
| 79 |
.. _SettingsSpec.settings_spec: |
| 80 |
|
| 81 |
`settings_spec` |
| 82 |
a sequence of |
| 83 |
|
| 84 |
1. option group title (string or None) |
| 85 |
|
| 86 |
2. description (string or None) |
| 87 |
|
| 88 |
3. option tuples with |
| 89 |
|
| 90 |
a) help text |
| 91 |
b) options string(s) |
| 92 |
c) dictionary with keyword arguments for `OptionParser.add_option()`_ |
| 93 |
and an optional "validator", a `frontend.validate_*()` function |
| 94 |
that processes the values (e.g. convert to other data types). |
| 95 |
|
| 96 |
For examples, see the source of ``frontend.OptionParser.settings_spec`` |
| 97 |
or the `settings_spec` attributes of the Docutils components_. |
| 98 |
|
| 99 |
.. _SettingsSpec.settings_defaults: |
| 100 |
|
| 101 |
`settings_defaults` |
| 102 |
for purely programmatic settings |
| 103 |
(not accessible from command line and configuration files). |
| 104 |
|
| 105 |
.. _SettingsSpec.settings_default_overrides: |
| 106 |
|
| 107 |
`settings_default_overrides` |
| 108 |
to override defaults for settings |
| 109 |
defined in other components' `setting_specs`. |
| 110 |
|
| 111 |
`relative_path_settings` |
| 112 |
listing settings containing filesystem paths. |
| 113 |
|
| 114 |
`config_section` |
| 115 |
the configuration file section specific to this |
| 116 |
component. |
| 117 |
|
| 118 |
`config_section_dependencies` |
| 119 |
lists configuration files sections |
| 120 |
that should also be read (before the `config_section`). |
| 121 |
|
| 122 |
.. _active sections: |
| 123 |
|
| 124 |
The last two attributes define which configuration file sections are "active". |
| 125 |
See also `Configuration File Sections & Entries`_ in the `Docutils |
| 126 |
Configuration`_ guide. |
| 127 |
|
| 128 |
|
| 129 |
Glossary |
| 130 |
======== |
| 131 |
|
| 132 |
.. _component: |
| 133 |
|
| 134 |
components |
| 135 |
---------- |
| 136 |
|
| 137 |
Docutils front-ends and applications combine a selection of *components* |
| 138 |
of the `Docutils Project Model`_ (reader, parser, writer). |
| 139 |
|
| 140 |
All components inherit the `SettingsSpec`_ base class. |
| 141 |
This means that all instances of ``readers.Reader``, ``parsers.Parser``, and |
| 142 |
``writers.Writer`` are also instances of ``docutils.SettingsSpec``. |
| 143 |
|
| 144 |
For the determination of runtime settings, ``frontend.OptionParser`` and |
| 145 |
applications providing a `SettingsSpec`_ instance via the `settings |
| 146 |
specification arguments`_ of the `Publisher convenience functions`_ |
| 147 |
are treated as components as well. |
| 148 |
|
| 149 |
|
| 150 |
settings_spec |
| 151 |
------------- |
| 152 |
|
| 153 |
The name ``settings_spec`` may refer to |
| 154 |
|
| 155 |
a) an instance of the SettingsSpec_ class, |
| 156 |
b) the data structure `SettingsSpec.settings_spec`_ which is used to |
| 157 |
store settings details, or |
| 158 |
c) the `"settings_spec" argument`_ of the Publisher convenience functions. |
| 159 |
|
| 160 |
|
| 161 |
.. References: |
| 162 |
|
| 163 |
.. _Publisher: publisher.html#publisher |
| 164 |
.. _Publisher convenience functions: |
| 165 |
publisher.html#publisher-convenience-functions |
| 166 |
.. _settings specification arguments: publisher.html#settings-specification |
| 167 |
.. _"settings_spec" argument: publisher.html#settings-spec |
| 168 |
.. _front-end tools: ../user/tools.html |
| 169 |
.. _configuration files: |
| 170 |
.. _Docutils Configuration: ../user/config.html#configuration-files |
| 171 |
.. _configuration file section: |
| 172 |
.. _Configuration File Sections & Entries: |
| 173 |
../user/config.html#configuration-file-sections-entries |
| 174 |
.. _Docutils Project Model: ../peps/pep-0258.html#docutils-project-model |
| 175 |
.. _Reader: ../peps/pep-0258.html#reader |
| 176 |
.. _Runtime Settings Processing: ../dev/runtime-settings-processing.html |
| 177 |
|
| 178 |
.. _optparse: https://docs.python.org/dev/library/optparse.html |
| 179 |
.. _argparse: https://docs.python.org/dev/library/argparse.html |
| 180 |
.. _OptionParser.add_option(): |
| 181 |
https://docs.python.org/dev/library/optparse.html |
| 182 |
#optparse.OptionParser.add_option |