Auto-discovery of configurations for easy inline use
Project description
[![Build Status](https://travis-ci.org/internap/python-config-probe.svg?branch=master)](https://travis-ci.org/internap/python-config-probe)
[![PyPI version](https://badge.fury.io/py/python-config-probe.svg)](http://badge.fury.io/py/python-config-probe)
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 = probe(
path="path/to/my/files",
patterns=["path/*/file.yaml"]
)
Use it:
print config.mynamespace.key
## Parameters
- **path**
Initial path to probe. 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 (*) to find where are the configuration files.
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 find 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
## 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 probed. 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!
[![PyPI version](https://badge.fury.io/py/python-config-probe.svg)](http://badge.fury.io/py/python-config-probe)
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 = probe(
path="path/to/my/files",
patterns=["path/*/file.yaml"]
)
Use it:
print config.mynamespace.key
## Parameters
- **path**
Initial path to probe. 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 (*) to find where are the configuration files.
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 find 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
## 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 probed. 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
config-probe-0.0.2.tar.gz
(9.2 kB
view details)
File details
Details for the file config-probe-0.0.2.tar.gz
.
File metadata
- Download URL: config-probe-0.0.2.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a61ae66fea6d1da625f27d486746aee2c34f5b29f9d62581660b4b721ef1911 |
|
MD5 | 569ecabf917ffaacc677c884dfe67cae |
|
BLAKE2b-256 | 7f1c83c45b9f085f27e81fd5a88c9c65a80164c1cce22d11afb40c6b9fd7ec3b |