lundybernard / batconf Goto Github PK
View Code? Open in Web Editor NEWApplication configuration tool from the BAT project
License: MIT License
Application configuration tool from the BAT project
License: MIT License
Remove the path and mod arguments from the Configuration, and source .get methods. These should not be necessary, and we should be able to rely on the name argument to .get() being either a single key on that config object, or a dot-separated module path to the key.
When you have a sub_config
conf = get_config(GlobalConfig)
sub_config = conf.my_module
print(sub_config.item)
We expect the ENV path for an item to be BAT_MY_MODULE_ITEM
however, batconf.sources.env.py: EnvConfig currently looks for MY_MODULE_ITEM
We should also handle sub-modules recursively, for instance
conf.my_module.sub_module.item
should lookup BAT_MY_MODULE_SUB_MODULE_ITEM
whether regardless of which config we look it up from:
conf = get_config(GlobalConfig)
print(conf.mod_config.sub_mod_config.item)
mod_config = conf.my_module
print(mod_config.sub_mod_config.item)
sub_mod_config = mod_config.sub_module
print(sub_mod_config.item)
should all lookup the same ENV variable
Add a new source that can search a credential store, or config database.
the file source Already allows multiple configs at the top-level by setting its config_env
parameter. We want a similar mechanism to select a sub-config at runtime.
Related to: lundybernard/project_template/issues/4
Provide a helpful concise representation of the configuration object
It should represent the attribute tree, the value that will be returned, and source of each value
ex:
GlobalConfig
├─ submodule1
│ └─ key1: ENV -> 'value-from-env'
│ └─ key2: config.yaml -> 'value from config file'
│ └─ key3: default -> None
├─ submodule2
│ └─ key4: ARGS -> 'value from ARGS'
add install instructions for fresh dev env to Readme
pyYAML needs to be unpinned, or pumped to >= 6.0.1 to fix upstream issue yaml/pyyaml#601
Line 27 in 412297b
Currently, if a source returns a falsey value (False, None, 0, etc.) it will be ignored, and we will continue on to the next source. Falsey values can be valid configuration options, so we need to distinguish a valid None
value in a config from a value Not Found None
.
Test Cases:
False
and None
values.True
values should be over-written by False
values that are set in a higher priority sourceWhen a FileConfig source is included in the Configuration source_list, but a file is not provided by the user, or found during FileConfig.init, looking up an attribute throws the following error.
File "/venv/lib/python3.9/site-packages/batconf/manager.py", line 42, in __getattr__
return self._get_config_opt(name, self._mod_)
File "/venv/lib/python3.9/site-packages/batconf/manager.py", line 45, in _get_config_opt
if value := self._config_sources.get(key, path=path):
File "/venv/lib/python3.9/site-packages/batconf/source.py", line 17, in get
if value := source.get(key, path):
File "/venv/lib/python3.9/site-packages/batconf/sources/file.py", line 38, in get
if not (conf := conf.get(k)):
AttributeError: 'str' object has no attribute 'get'
FIX: missing keys in the config file should return None
, not raise an AttributeError. If the file is missing all FileConfig.get should always return None
provide a helpful string representation of the Configuration object
Since repr should be used for debugging and unambiguous, it should display all the sources, and all of the attribute: value pairs that we know of from those sources. This can probably be accomplished fairly easily by printing the dict values of the configuration and sources recursively
ex:
<batconf.manager.Configuration object at 0x7f2c3e68e8f0>: {
_config_class: '__main__.GlobalConfig'
_config_sources: [
<batconf.sources.dataclass.DataclassConfig at 0x7f2c3e68cfa0>: {
'_root': '__main__',
'_data': {
'key': 'value',
'key2': None
}
},
]
}
pypi's project page should link to this repo
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.