Skip to content

Commit 52b0030

Browse files
Add api_reference
1 parent af2d6ca commit 52b0030

File tree

10 files changed

+51
-25
lines changed

10 files changed

+51
-25
lines changed

docs/nitpick-exceptions

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
py:class InputData
2+
3+
# external references that Sphinx cannot resolve
4+
py:class yaml.nodes.MappingNode
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. automodule:: layered_config_tree.exceptions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
API Reference
2+
=============
3+
4+
.. automodule:: layered_config_tree
5+
6+
.. toctree::
7+
:maxdepth: 1
8+
:glob:
9+
10+
*

docs/source/api_reference/main.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. automodule:: layered_config_tree.main
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. automodule:: layered_config_tree.utilities

docs/source/conf.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
# ones.
5151
extensions = [
5252
"sphinx.ext.autodoc",
53+
"sphinx_autodoc_typehints",
5354
"sphinx.ext.intersphinx",
5455
"sphinx.ext.doctest",
5556
"sphinx.ext.todo",
@@ -221,9 +222,9 @@
221222
nitpicky = True
222223

223224
nitpick_ignore: list[tuple[str, str]] = []
224-
# for line in open("../nitpick-exceptions"):
225-
# if line.strip() == "" or line.startswith("#"):
226-
# continue
227-
# dtype, target = line.split(None, 1)
228-
# target = target.strip()
229-
# nitpick_ignore.append((dtype, target))
225+
for line in open("../nitpick-exceptions"):
226+
if line.strip() == "" or line.startswith("#"):
227+
continue
228+
dtype, target = line.split(None, 1)
229+
target = target.strip()
230+
nitpick_ignore.append((dtype, target))

docs/source/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ Layered Config Tree Documentation
55
Layered Config Tree is a configuration structure which supports cascading layers.
66

77
TBD.
8+
9+
10+
.. toctree::
11+
:maxdepth: 2
12+
13+
api_reference/index
14+

src/layered_config_tree/exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""
2+
==========
3+
Exceptions
4+
==========
5+
6+
"""
7+
18
from typing import Any
29

310

src/layered_config_tree/main.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
from __future__ import annotations
3131

32-
import warnings
3332
from collections.abc import Iterable
3433
from pathlib import Path
3534
from typing import Any
@@ -62,7 +61,7 @@ class ConfigNode:
6261
6362
A :class:`ConfigNode` may only have a value set at each layer once.
6463
Attempts to set a value at the same layer multiple times will result in
65-
a :class:`DuplicatedConfigurationError`.
64+
a :class:`~layered_config_tree.exceptions.DuplicatedConfigurationError`.
6665
6766
The :class:`ConfigNode` will record all values set and the source they
6867
are set from. This sort of provenance with configuration data greatly
@@ -110,7 +109,6 @@ def freeze(self) -> None:
110109
111110
This can be used to create a contract around when the configuration is
112111
modifiable.
113-
114112
"""
115113
self._frozen = True
116114

@@ -158,7 +156,6 @@ def update(self, value: Any, layer: str | None, source: str | None) -> None:
158156
DuplicatedConfigurationError
159157
If a value has already been set at the provided layer or a value
160158
is already in the outermost layer and no layer has been provided.
161-
162159
"""
163160
if self._frozen:
164161
raise ConfigurationError(
@@ -193,8 +190,8 @@ def _get_value_with_source(self, layer: str | None) -> tuple[str | None, Any]:
193190
194191
Returns
195192
-------
196-
The (source, value) tuple at the specified layer or, if no layer is
197-
specified, at the outermost (highest priority) layer.
193+
The (source, value) tuple at the specified layer or, if no layer is
194+
specified, at the outermost (highest priority) layer.
198195
199196
Raises
200197
------
@@ -247,6 +244,7 @@ class ConfigIterator:
247244
An iterator for a LayeredConfigTree object.
248245
249246
This iterator is used to iterate over the keys of a LayeredConfigTree object.
247+
250248
"""
251249

252250
def __init__(self, config_tree: LayeredConfigTree):
@@ -319,7 +317,6 @@ def freeze(self) -> None:
319317
320318
This is useful for loading and then freezing configurations that
321319
should not be modified at runtime.
322-
323320
"""
324321
self.__dict__["_frozen"] = True
325322
for child in self.values():
@@ -353,7 +350,6 @@ def to_dict(self) -> dict[str, Any]:
353350
"""Converts the LayeredConfigTree into a nested dictionary.
354351
355352
All metadata is lost in this conversion.
356-
357353
"""
358354
result = {}
359355
for name, child in self.items():
@@ -386,9 +382,9 @@ def get(
386382
387383
Returns
388384
-------
389-
The value at the key or nested keys and at the requested layer (the outer, by default).
390-
``default_value`` (None, by default) is returned if the full key path *except
391-
for the final key* exists at an *explicitly-requested* layer.
385+
The value at the key or nested keys and at the requested layer (the outer, by default).
386+
``default_value`` (None, by default) is returned if the full key path *except
387+
for the final key* exists at an *explicitly-requested* layer.
392388
393389
Raises
394390
------
@@ -421,8 +417,8 @@ def get_tree(self, keys: str | list[str]) -> LayeredConfigTree:
421417
422418
Returns
423419
-------
424-
The ``LayeredConfigTree`` located at the key or key path provided starting
425-
from the outermost layer.
420+
The ``LayeredConfigTree`` located at the key or key path provided starting
421+
from the outermost layer.
426422
427423
Raises
428424
------
@@ -495,7 +491,6 @@ def update(
495491
DuplicatedConfigurationError
496492
If a value has already been set at the provided layer or a value
497493
is already in the outermost layer and no layer has been provided.
498-
499494
"""
500495
if data is not None:
501496
data_dict, source = self._coerce(data, source)
@@ -560,7 +555,6 @@ def _set_with_metadata(
560555
DuplicatedConfigurationError
561556
If a value has already been set at the provided layer or a value
562557
is already in the outermost layer and no layer has been provided.
563-
564558
"""
565559
if self._frozen:
566560
raise ConfigurationError(

src/layered_config_tree/utilities.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,22 @@ class SafeLoader(yaml.SafeLoader):
6161
"""A yaml.SafeLoader that restricts duplicate keys."""
6262

6363
def construct_mapping(
64-
self, node: yaml.MappingNode, deep: bool = False
64+
self, node: yaml.nodes.MappingNode, deep: bool = False
6565
) -> dict[Hashable, Any]:
6666
"""Constructs the standard mapping after checking for duplicates.
6767
6868
Raises
6969
------
70-
DuplicateKeysInYAMLError
70+
DuplicatedConfigurationError
7171
If duplicate keys within the same level are detected in the YAML file
7272
being loaded.
7373
7474
Notes
7575
-----
7676
A key is considered a duplicate only if it is the same as another key
77-
_at the same level in the YAML_.
77+
*at the same level in the YAML*.
7878
79-
This raises upon the _first_ duplicate key found; other duplicates may exist
79+
This raises upon the *first* duplicate key found; other duplicates may exist
8080
(in which case a new error will be raised upon re-loading of the YAML file
8181
once the duplicate is resolved).
8282
"""

0 commit comments

Comments
 (0)