config.processor.component

组件配置处理器

在 0.2.0 版本加入.

Classes

ComponentMetaParser

默认元信息解析器

ComponentSL

组件模式配置处理器

Module Contents

class ComponentMetaParser

Bases: config.abc.ABCMetaParser[ComponentMetaParser.D, config.basic.component.ComponentMeta[ComponentMetaParser.D]]

默认元信息解析器

__eq__(other: Any) bool
convert_config2meta(meta_config: D) config.basic.component.ComponentMeta[D]

解析元配置

参数:

meta_config (D) -- 元配置

返回:

元数据

返回类型:

ComponentMeta[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__

__eq__(other: Any) bool
__hash__() int
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处理器

参数:

file_name (str) -- 配置文件名

返回:

格式化后的文件名

返回类型:

str

默认实现:
  • 遍历 BasicCompressedConfigSL

  • 如果为 strfile_name.endswith 成立则返回移除后缀后的结果

  • 如果为 re.PatternPattern.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) -- 配置文件名

返回:

配置对象

返回类型:

ABCConfigFile

在 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) -- 配置文件名

返回:

配置对象

返回类型:

ABCConfigFile

抛出:

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 以支持指定成员的配置解析格式

namespace_formatter(namespace: str, file_name: str) str

格式化命名空间以传递给其他SL处理器

参数:
  • namespace (str) -- 配置的命名空间

  • file_name (str) -- 配置文件名

返回:

格式化后的命名空间

返回类型:

str

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

保存指定命名空间的配置

参数:
__slots__ = ()
_cleanup_registry: bool = True

自动清理为了传递SL处理所加入配置池的配置文件

_reg_alias: str | None = None
create_dir = True
meta_file = '__meta__'
meta_parser: config.abc.ABCMetaParser[Any, config.basic.component.ComponentMeta[Any]] = None
property processor_reg_name: str

SL处理器的默认注册名

raises
property reg_alias: str | None

处理器的别名

property reg_name: str

处理器的注册名

supported_file_classes
返回:

支持的配置文件类

在 0.2.0 版本加入.

property supported_file_patterns: tuple[str, Ellipsis]
返回:

支持的文件名匹配

在 0.2.0 版本发生变更: 重命名 file_extsupported_file_patterns