蟒蛇构造
ConfigIt的Python项目详细描述
configit是mit授权的python配置库 在镜头前害羞的人。
python是关于dicts的,所以我们为什么要满足于INIs?
功能
所有配置文件都是本地python文件。
使用configit,您可以将这些文件作为模块或文件读取 并返回具有属性访问权限的字典。
configit最强大的功能之一是它能够使用其他 配置中的配置。
安装
要安装configit,只需:
$ pip install configit
API文档
- configit.conf_from_file(文件路径)
- 读取字符串文件路径并返回configdict。
filepath = r'tests/configs/default.py' config = conf_from_file(filepath) assert config.config_dict.name == 'default'
- configit.conf_from_module(module)
- 读取导入的模块并返回configdict。
import tests.configs.module_config config = conf_from_module(tests.configs.module_config) assert config.config_dict.name == 'module_config'
- configit.conf_from_dict(conf_dict)
读取字典并返回configdict。
configdict可通过属性和键访问。
config = dict(answer=42) config = configit.conf_from_dict(config) assert config.answer == 42
- 配置。使用(配置源)
在一个python配置中,您可以导入另一个python配置。 导入的配置将更新导入配置的本地名称空间。 这意味着可以在本地配置中访问子配置中的值。
这对于只需要更改一些项的锅炉板配置非常有用。
file_supplement.py contents:
answer=42
file.py contents:
import configit configit.use('file_supplement.py')
Code using configit to get the configuration:
import configit config = conf_from_file('file.py') assert config.answer == 42
订单很重要!
file_supplement.py contents:
answer=42
file.py contents:
import configit configit.use('file_supplement.py') answer=5
Code using configit to get the configuration:
import configit config = conf_from_file('file.py') assert config.answer == 5
有关更多示例,请参阅包含的测试。
贡献
在github上分叉the repository,开始对development分支(或其分支)进行更改。
通过运行:
$ python setup.py develop
哈克顿,舞会!
编写一个测试,显示错误已修复或功能按预期工作。
运行测试:
$ python setup.py test
发送一个pull请求并对维护程序进行bug操作,直到它被合并并发布。:)请确保将自己添加到AUTHORS。