配置加载和解析包
configyaml的Python项目详细描述
用法
基本的使用模式是扩展这些类来创建自己的类。
您需要加载器:
fromconfigyamlimportloaderfrom.config.rootimportRootclassSibbellConfigLoader(loader.ConfigLoader):config_root_class=Root
然后使用其他类设计配置。至少需要1个作为根类:
fromconfigyaml.configimportDictNodefrom.dependenciesimportDependenciesfrom.notificationsimportNotificationsclassRoot(DictNode):"""Root of the yaml file"""def__init__(self,*args,**kwargs):self._dict_fields={'dependencies':{'class':Dependencies,'required':True,'default':[],},'notifications':{'class':Notifications,'required':True,# no point right now if no notifications'default':[],}}super(Root,self).__init__(*args,**kwargs)def_context_to_inject(self):"""Make dependencies list available to notifcations"""return{'dependencies':self.dependencies}
然后要使用它,只需使用配置文本内容创建加载程序:
loader=SibbellConfigLoader(yaml_text)# can now access the configuration and any other properties/method added to their classesloader.is_valid()loader.errorsloader.config_root.dependencies
历史
0.5.1(2018-03-30)
- 修复listnode为子节点传递错误的yaml节点
0.5.0(2018-03-30)
- 添加对“变量”的支持
0.4.1(2018-01-31)
- 赋予dictnode对父实例和上下文的默认访问权限
- 更新自述徽章
0.4.0(2017-06-07)
- 添加regexnode
- dictnode字段知道dict键是什么
0.3.0(2017-05-31)
- 添加类型snode
- 添加boolnode
- 使用yaml.safe_load
- 允许dictnode字段的默认值为none
0.2.0(2017-04-05)
- 清理包发布工具和文档
- 修复一些损坏的文档
- 为类启动一些基本的sphinx文档
0.1.0(2017-03-30)
- pypi上的第一个版本。