Provide an auto-discovery process for configurations
Project description
Mission
Provide an auto-discovery process of configurations for simple code use. Given a path and a list of pattern, the result config will be a shortcut to any config.
Usage
Setup:
config = mixin(
path="path/to/my/files",
patterns=["path/(*)/file.yaml"]
)
Use it:
print config.mynamespace.key
Parameters
-
path
Initial path to configs. Patterns will be tested against the file structure underneath the path, and it will be ignored in determining the namespacing.
-
patterns
A list of file paths containing (or not) placeholders "(*)" o find where the configuration files are located. The patterns definition order defines which keys has the priority, the last one being the most relevant.
Each placeholder in the path will result in a namespace in the resulting config. So let's say you have a pattern
dir1/(*)/dir2/(*).yaml
If this pattern finds the file : "dir1/ns1/dir2/file.yaml" that contains "key: 'value'", the resulting config will be
config.ns1.file.key == "value"
now if the pattern was
dir1/ns1/dir2/file.yaml
for the same file, the resulting config would simply be
config.key == "value"
so you can use placeholders "(*)" to namespace the resulting config and use "*" without the parenthesis to have a variable path without the namespacing
dir1/(*)/dir2/*.yaml config.ns1.key == "value"
Mocking the probing
Your unit test can have your code use fake_probe instead to which to give a dict, and it will appear as if it was just mixed-in. Example:
config = fake_probe({
"ns1": {
"file": {
"key": "value"
}
}
})
# then
config.ns1.file.key == "value"
Contributing
Feel free to raise issues and send some pull request, we'll be happy to look at them!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file config_mixin-1.0.0.tar.gz
.
File metadata
- Download URL: config_mixin-1.0.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3971b60a377c12ec3ed33e754f8448abd730bf9134238b026b210cc34a40bae7 |
|
MD5 | c425047365ac2320a0ac9271ed6eee5b |
|
BLAKE2b-256 | b561eb127873a7160e375b1526e9c5926b8125bea0f3c875a54ccc6290d2f7d8 |
Provenance
The following attestation bundles were made for config_mixin-1.0.0.tar.gz
:
Publisher:
publish.yml
on stephanerobert/config-mixin
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
config_mixin-1.0.0.tar.gz
- Subject digest:
3971b60a377c12ec3ed33e754f8448abd730bf9134238b026b210cc34a40bae7
- Sigstore transparency entry: 146544217
- Sigstore integration time:
- Predicate type:
File details
Details for the file config_mixin-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: config_mixin-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c54a07de7c0e85640e1bf6010985c3a720e899281509a057f010fceb3e346bf |
|
MD5 | 9aed63faad163c45eea44ec70ced2824 |
|
BLAKE2b-256 | ff66be2918b3c1f575ea7b169ba8c7c2aab9320c40a598bc626ef829d8c4272b |
Provenance
The following attestation bundles were made for config_mixin-1.0.0-py3-none-any.whl
:
Publisher:
publish.yml
on stephanerobert/config-mixin
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
config_mixin-1.0.0-py3-none-any.whl
- Subject digest:
6c54a07de7c0e85640e1bf6010985c3a720e899281509a057f010fceb3e346bf
- Sigstore transparency entry: 146544218
- Sigstore integration time:
- Predicate type: