Skip to content

Commit efc6a9d

Browse files
committed
Add "Reading from multiple files" from #87
1 parent 02d5a53 commit efc6a9d

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

docs/mkdocs.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ repo_url: https://github.com/NetherlandsForensicInstitute/confidence/
66

77
theme:
88
name: material
9+
features:
10+
- navigation.tabs
11+
- navigation.tabs.sticky
912
palette:
1013
- media: '(prefers-color-scheme: light)'
1114
scheme: default
@@ -20,6 +23,15 @@ theme:
2023
icon: material/weather-night
2124
name: Switch to light mode
2225

26+
markdown_extensions:
27+
- pymdownx.highlight:
28+
anchor_linenums: true
29+
line_spans: __span
30+
pygments_lang_class: true
31+
- pymdownx.inlinehilite
32+
- pymdownx.snippets
33+
- pymdownx.superfences
34+
2335
plugins:
2436
- search
2537
- mkdocstrings:

docs/usage/loading.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Although confidence is internally divided in a number of modules, all of the fun
66
# manually creating a Configuration object from a dict of values is about as
77
# simple as it sounds:
88
config = confidence.Configuration({
9-
'service.host': 'example.com',
10-
'service.port': 443,
9+
'service.host': 'example.com',
10+
'service.port': 443,
1111
})
1212
# suppose there's a function connect that takes two arguments
1313
# we can connect to the configured host and port as such:
@@ -41,3 +41,31 @@ config = confidence.loadf('path/to/file.yaml')
4141
# the result is the same as the example above, we can use config.service like we would a dict
4242
connection = connect(**config.service)
4343
```
44+
45+
## Reading from multiple files
46+
47+
If you split your configuration over multiple files as they contain configuration for different things,
48+
like a service to connect to and some local paths to store data, confidence can load them both as if they were one:
49+
50+
```yaml
51+
# some system-wide configuration in /etc/paths.yaml
52+
paths:
53+
data: /storage/data
54+
backup: /mnt/backup/data
55+
```
56+
57+
```yaml
58+
# service configuration as before, stored in path/to/service.yaml
59+
service.host: example.com
60+
service.port: 443
61+
```
62+
63+
```python
64+
# loadf can take multiple files, the contents of which are combined into a
65+
# single Configuration object
66+
config = confidence.loadf('/etc/paths.yaml', 'path/to/service.yaml')
67+
# there's still something to connect to the service
68+
connection = connect(**config.service)
69+
# and some extra things that configure the place to backup to
70+
connection.backup_to(config.paths.backup)
71+
```

0 commit comments

Comments
 (0)