Skip to content

Commit ea3ec51

Browse files
committed
Adjust user doc: config
1 parent cbac198 commit ea3ec51

2 files changed

Lines changed: 131 additions & 11 deletions

File tree

docs/source/glossary.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ For Python specific terms, look into:
141141

142142
See class :class:`~docbuild.models.product.Product`.
143143

144+
Pydantic
145+
A Python library for data validation and settings management using Python type annotations. It provides a way to define data models with strict type checking and validation rules, making it easier to ensure that the data your application works with is correct and consistent.
146+
147+
See https://pydantic.dev/
148+
144149
:file:`pyproject.toml`
145150
A configuration file used in Python project to define build system
146151
requirements and project metadata.

docs/source/user/config.rst

Lines changed: 126 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Configuring the Tool
55

66
.. note::
77

8-
To prevent accidental commits of sensitive information, all configuration files matching the :file:`env.*.toml` pattern in the root directory are ignored by git. However, this rule does not apply to files within the :file:`etc/` directory.
8+
To prevent accidental commits of sensitive information, all configuration files matching the :file:`env.*.toml` pattern in the root directory are ignored by Git. However, this rule does not apply to files within the :file:`etc/` directory.
99

1010
Use separate TOML files to define the configuration for each of your environments. To avoid confusion, name each file according to its specific purpose. For instance, use :file:`env.devel.toml` for development, :file:`env.staging.toml` for staging, and :file:`env.production.toml` for production.
1111

@@ -21,26 +21,141 @@ To use your configuration file, follow these steps one time:
2121

2222
#. Adjust the path ``paths.root_config_dir``. Use the path from :ref:`get-xml-config`. The rest can stay as it is.
2323

24-
#. Specific the configuration with the global option ``--env-config``.
24+
#. Specify the configuration with the global option ``--env-config``.
2525

26-
To deal with different environments without having to type the full command each time, create aliases in your shell. This allows you to quickly switch between configurations without needing to remember the exact command syntax.
2726

28-
.. code-block:: shell-session
29-
:caption: Example aliases for different configuration files
30-
:name: docbuild-aliases
27+
.. _config-key-naming-conventions:
3128

32-
alias docbuild-prod='docbuild --env-config env.production.toml'
33-
alias docbuild-test='docbuild --env-config env.testing.toml'
34-
alias docbuild-dev='docbuild --env-config env.devel.toml'
29+
Key Naming conventions
30+
----------------------
31+
32+
The keys follow specific naming conventions to indicate their purpose and expected value types. Here are some common patterns whereas the asterisk
33+
(``*``) represents a variable part of the key:
34+
35+
* ``*_dir``: Contains a directory.
36+
37+
* ``tmp_*``: Indicates a temporary path.
38+
39+
* ``*_dyn``: Denotes a dynamic value that is expected to be resolved at runtime.
40+
41+
Directories are created automatically when the script runs. Additionally,
42+
the script checks if the specified paths are readable, writeable and belongs
43+
to the user running the script.
44+
45+
46+
.. _config-validation:
47+
48+
Validating the Configuration
49+
-----------------------------
50+
51+
Before docbuild executes any commands, it validates the provided configuration
52+
file against a predefined :term:`Pydantic` model.
53+
54+
The validation checks for different aspects of the configuration, such as:
55+
56+
* Presence of mandatory keys.
57+
* Correct data types (for example, strings, integers, lists).
58+
* Valid paths and if they exist on the filesystem and are writable when
59+
required.
60+
* Correct use of placeholders.
61+
62+
63+
.. TODO: Add a link to the TOML env config reference, add an example of
64+
a validation error message, and explain how to fix common issues.
65+
66+
67+
.. _config-placeholders:
68+
69+
Using Placeholders
70+
------------------
71+
72+
Docbuild supports the use of placeholders in the configuration file.
73+
Two types of placeholders are supported:
74+
75+
* **Static placeholders** (Syntax ``{placeholder}``)
76+
77+
They are used to reference *other parts* of the configuration.
78+
For example, assume you have a configuration key ``paths.root_config_dir`` that defines the root directory for configuration files. You can use a static placeholder like ``{paths.root_config_dir}`` in other parts of the configuration to refer to this value.
79+
80+
This allows you to maintain consistency and avoid repeating the same path multiple times in your configuration file.
81+
82+
83+
* **Dynamic placeholders** (Syntax ``{{placeholder}}``)
84+
85+
These types of placeholder cannot and must not be replaced. They are meant to be used as *templates* for values that will be resolved at runtime. For example, you might have a placeholder like ``{{product}}`` that is intended to be replaced with the actual product name when the docbuild tool runs.
86+
87+
This allows for greater flexibility and adaptability in your configuration, as the same configuration file can be used across different products or environments without needing to hardcode specific values.
88+
89+
These types of placeholder make it easier to manage and maintain your configuration files, as they allow you to centralize key values and create reusable templates for dynamic content.
90+
91+
Static placeholders follow a specific syntax:
92+
93+
* **Regular name** (Syntax ``{placeholder}``)
94+
95+
A regular name refers to a another key in the same section:
96+
97+
.. code-block:: toml
98+
:emphasize-lines: 3
99+
100+
[paths]
101+
root_config_dir = "~/repos/GL/susedoc/docserv-config"
102+
jinja_dir = "{root_config_dir}/jinja-doc-suse-com"
103+
104+
In the previous example, the key ``jinja_dir`` uses a static placeholder
105+
``{root_config_dir}`` to reference the value of the same key
106+
``root_config_dir`` within the same section.
107+
108+
* **Section name** (Syntax ``{section.key}``)
109+
110+
A section name refers to a key in another section:
111+
112+
.. code-block:: toml
113+
:emphasize-lines: 5
114+
115+
[server]
116+
name = "doc-example-com"
117+
118+
[path]
119+
base_server_cache_dir = "{base_cache_dir}/{server.name}"
120+
121+
In this example, the key ``base_server_cache_dir`` uses the
122+
static placeholder ``{server.name}`` to reference the value of the
123+
key ``name`` in the ``server`` section.
124+
125+
If you have nested sections, use the dot notation to reference the keys.
126+
For example, ``section.subsection.key``.
127+
128+
129+
.. _config-viewing-docbuild-config-env:
35130

36131
Viewing the Environment Configuration
37132
-------------------------------------
38133

39-
To see how ``docbuild`` interprets your environment configuration, use the ``config env`` subcommand. This is particularly useful for verifying that all placeholders (like ``{{product}}`` or ``{{lang}}``) have been correctly resolved into absolute paths.
134+
To see how ``docbuild`` interprets your environment configuration, use the
135+
``config env`` subcommand. This is particularly useful for verifying that all
136+
static placeholders have been correctly resolved into absolute paths.
40137

41138
.. code-block:: shell-session
42139
:caption: Displaying the resolved environment configuration
43140
44-
docbuild config env
141+
docbuild --env-config=YOUR_TOML_CONFIG config env
45142
46143
If the configuration contains errors—such as missing mandatory keys or invalid data types—the command will output a validation error detailing what needs to be fixed.
144+
145+
146+
.. _config-use-multiple-env-configs:
147+
148+
Using Multiple Environment Configurations
149+
-----------------------------------------
150+
151+
To deal with different environments without having to type the full command
152+
each time, create aliases in your shell. This allows you to quickly switch
153+
between configurations without needing to remember the exact command syntax.
154+
155+
.. code-block:: shell-session
156+
:caption: Example aliases for different configuration files
157+
:name: docbuild-aliases
158+
159+
alias docbuild-prod='docbuild --env-config env.production.toml'
160+
alias docbuild-test='docbuild --env-config env.testing.toml'
161+
alias docbuild-dev='docbuild --env-config env.devel.toml'

0 commit comments

Comments
 (0)