config.processor.component¶
组件配置处理器
在 0.2.0 版本加入.
Classes¶
默认元信息解析器 |
|
组件模式配置处理器 |
Module Contents¶
- class ComponentMetaParser¶
Bases:
config.abc.ABCMetaParser[ComponentMetaParser.D,config.basic.component.ComponentMeta[ComponentMetaParser.D]]默认元信息解析器
- convert_config2meta(meta_config: D) config.basic.component.ComponentMeta[D]¶
解析元配置
- 参数:
meta_config (D) -- 元配置
- 返回:
元数据
- 返回类型:
- convert_meta2config(meta: config.basic.component.ComponentMeta[D]) D¶
解析元数据
- 参数:
meta (ComponentMeta[D]) -- 元数据
- 返回:
元配置
- 返回类型:
D
- validator(meta: config.basic.component.ComponentMeta[D], *args: Any) config.basic.component.ComponentMeta[D]¶
元数据验证器
- __hash__ = None¶
- __slots__ = ()¶
- _validator: config.main.RequiredPath[dict[str, Any], ComponentMetaParser.D]¶
- class ComponentSL(*, reg_alias: str | None = None, create_dir: bool = True, meta_parser: config.abc.ABCMetaParser[Any, config.basic.component.ComponentMeta[Any]] | None = None, meta_file: str = '__meta__')¶
Bases:
config.main.BasicChainConfigSL组件模式配置处理器
- 参数:
reg_alias (str | None) -- 处理器别名
create_dir (bool) -- 是否创建目录
meta_parser (ABCMetaParser[Any, ComponentMeta[Any]] | None) -- 元数据解析器
meta_file (str) -- 元信息文件名
在 0.3.0 版本发生变更: 重构属性
initial_file为参数meta_file并更改默认值__init__为__meta__- after_save(config_pool: config.abc.ABCConfigPool, config_file: config.abc.ABCConfigFile[Any], file_path: str, root_path: str, namespace: str, file_name: str) None¶
保存后处理
- 参数:
config_pool (ABCConfigPool) -- 配置池
config_file (ABCConfigFile[Any]) -- 配置文件
file_path (str) -- 文件路径
root_path (str) -- 根路径
namespace (str) -- 命名空间
file_name (str) -- 文件名
- before_load(config_pool: config.abc.ABCConfigPool, file_path: str, root_path: str, namespace: str, file_name: str) None¶
加载前处理
- 参数:
config_pool (ABCConfigPool) -- 配置池
file_path (str) -- 文件路径
root_path (str) -- 根路径
namespace (str) -- 命名空间
file_name (str) -- 文件名
- filename_formatter(file_name: str) str¶
格式化文件名以传递给其他SL处理器
- 默认实现:
遍历
BasicCompressedConfigSL如果为
str且file_name.endswith成立则返回移除后缀后的结果如果为
re.Pattern且Pattern.fullmatch(file_name)成立则返回Pattern.sub(file_name, "")直接返回
- initialize(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) config.basic.core.ConfigFile[config.basic.component.ComponentConfigData[Any, Any]]¶
初始化一个受SL处理器支持的配置文件
- 参数:
processor_pool (ABCSLProcessorPool) -- 配置池
root_path (str) -- 保存的根目录
namespace (str) -- 配置的命名空间
file_name (str) -- 配置文件名
- 返回:
配置对象
- 返回类型:
在 0.2.0 版本加入.
- load(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) config.abc.ABCConfigFile[Any]¶
加载处理器
- 参数:
processor_pool (ABCSLProcessorPool) -- 配置池
root_path (str) -- 保存的根目录
namespace (str) -- 配置的命名空间
file_name (str) -- 配置文件名
- 返回:
配置对象
- 返回类型:
- 抛出:
FailedProcessConfigFileError -- 处理配置文件失败
在 0.2.0 版本发生变更: 删除参数
config_file_cls添加参数
processor_pool
- load_file(config_pool: config.abc.ABCConfigPool, namespace: str, file_name: str, *args: Any, **kwargs: Any) config.basic.core.ConfigFile[config.basic.component.ComponentConfigData[Any, Any]]¶
加载指定命名空间的配置
- 参数:
config_pool (ABCConfigPool) -- 配置池
namespace (str) -- 命名空间
file_name (str) -- 文件名
可选参数¶
- param config_formats:
指定成员配置格式
- type config_formats:
Mapping[str | None, Any]
- return:
配置文件
- rtype:
ConfigFile[ComponentConfigData[Any, Any]]
小心
传递SL处理前没有清理已经缓存在配置池里的配置文件,返回的可能不是最新数据
在 0.3.0 版本发生变更: 新增可选参数
config_formats以支持指定成员的配置解析格式
- register_to(config_pool: config.abc.ABCSLProcessorPool | None = None) Self¶
注册到配置池中
- 参数:
config_pool (ABCSLProcessorPool | None) -- 配置池
- 返回:
返回当前实例便于链式调用
- 返回类型:
Self
在 0.3.0 版本发生变更: 返回当前实例便于链式调用
- save(processor_pool: config.abc.ABCSLProcessorPool, config_file: config.abc.ABCConfigFile[Any], root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) None¶
保存处理器
- 参数:
processor_pool (ABCSLProcessorPool) -- 配置池
config_file (ABCConfigFile) -- 待保存配置
root_path (str) -- 保存的根目录
namespace (str) -- 配置的命名空间
file_name (str) -- 配置文件名
- 抛出:
FailedProcessConfigFileError -- 处理配置文件失败
在 0.2.0 版本发生变更: 添加参数
processor_pool
- save_file(config_pool: config.abc.ABCConfigPool, config_file: config.abc.ABCConfigFile[config.basic.component.ComponentConfigData[Any, Any] | config.basic.object.NoneConfigData], namespace: str, file_name: str, *args: Any, **kwargs: Any) None¶
保存指定命名空间的配置
- 参数:
config_pool (ABCConfigPool) -- 配置池
config_file (ABCConfigFile) -- 配置文件
namespace (str) -- 命名空间
file_name (str) -- 文件名
- __slots__ = ()¶
- create_dir = True¶
- meta_file = '__meta__'¶
- meta_parser: config.abc.ABCMetaParser[Any, config.basic.component.ComponentMeta[Any]] = None¶
- raises¶
- supported_file_classes¶
- 返回:
支持的配置文件类
在 0.2.0 版本加入.