config.processor.component ========================== .. py:module:: config.processor.component .. autoapi-nested-parse:: 组件配置处理器 .. versionadded:: 0.2.0 Classes ------- .. autoapisummary:: config.processor.component.ComponentMetaParser config.processor.component.ComponentSL Module Contents --------------- .. py:class:: ComponentMetaParser Bases: :py:obj:`config.abc.ABCMetaParser`\ [\ :py:obj:`ComponentMetaParser.D`\ , :py:obj:`config.basic.component.ComponentMeta`\ [\ :py:obj:`ComponentMetaParser.D`\ ]\ ] 默认元信息解析器 .. py:method:: __eq__(other: Any) -> bool .. py:method:: convert_config2meta(meta_config: D) -> config.basic.component.ComponentMeta[D] 解析元配置 :param meta_config: 元配置 :type meta_config: D :return: 元数据 :rtype: ComponentMeta[D] .. py:method:: convert_meta2config(meta: config.basic.component.ComponentMeta[D]) -> D 解析元数据 :param meta: 元数据 :type meta: ComponentMeta[D] :return: 元配置 :rtype: D .. py:method:: validator(meta: config.basic.component.ComponentMeta[D], *args: Any) -> config.basic.component.ComponentMeta[D] 元数据验证器 .. py:attribute:: __hash__ :value: None .. py:attribute:: __slots__ :value: () .. py:attribute:: _validator :type: config.main.RequiredPath[dict[str, Any], ComponentMetaParser.D] .. py: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: :py:obj:`config.main.BasicChainConfigSL` 组件模式配置处理器 :param reg_alias: 处理器别名 :type reg_alias: str | None :param create_dir: 是否创建目录 :type create_dir: bool :param meta_parser: 元数据解析器 :type meta_parser: ABCMetaParser[Any, ComponentMeta[Any]] | None :param meta_file: 元信息文件名 :type meta_file: str .. versionchanged:: 0.3.0 重构属性 ``initial_file`` 为参数 ``meta_file`` 并更改默认值 ``__init__`` 为 ``__meta__`` .. py:method:: __eq__(other: Any) -> bool .. py:method:: __hash__() -> int .. py:method:: 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 保存后处理 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param config_file: 配置文件 :type config_file: ABCConfigFile[Any] :param file_path: 文件路径 :type file_path: str :param root_path: 根路径 :type root_path: str :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str .. py:method:: before_load(config_pool: config.abc.ABCConfigPool, file_path: str, root_path: str, namespace: str, file_name: str) -> None 加载前处理 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param file_path: 文件路径 :type file_path: str :param root_path: 根路径 :type root_path: str :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str .. py:method:: filename_formatter(file_name: str) -> str 格式化文件名以传递给其他SL处理器 :param file_name: 配置文件名 :type file_name: str :return: 格式化后的文件名 :rtype: str 默认实现: - 遍历 :py:attr:`BasicCompressedConfigSL` - 如果为 ``str`` 且 ``file_name.endswith`` 成立则返回移除后缀后的结果 - 如果为 ``re.Pattern`` 且 ``Pattern.fullmatch(file_name)`` 成立则返回 ``Pattern.sub(file_name, "")`` - 直接返回 .. py:method:: 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处理器支持的配置文件 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 配置对象 :rtype: ABCConfigFile .. versionadded:: 0.2.0 .. py:method:: load(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) -> config.abc.ABCConfigFile[Any] 加载处理器 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 配置对象 :rtype: ABCConfigFile :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 删除参数 ``config_file_cls`` 添加参数 ``processor_pool`` .. py:method:: 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]] 加载指定命名空间的配置 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str 可选参数 ----------- :param config_formats: 指定成员配置格式 :type config_formats: Mapping[str | None, Any] :return: 配置文件 :rtype: ConfigFile[ComponentConfigData[Any, Any]] .. caution:: 传递SL处理前没有清理已经缓存在配置池里的配置文件,返回的可能不是最新数据 .. versionchanged:: 0.3.0 新增可选参数 ``config_formats`` 以支持指定成员的配置解析格式 .. py:method:: namespace_formatter(namespace: str, file_name: str) -> str 格式化命名空间以传递给其他SL处理器 :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :return: 格式化后的命名空间 :rtype: str .. py:method:: register_to(config_pool: config.abc.ABCSLProcessorPool | None = None) -> Self 注册到配置池中 :param config_pool: 配置池 :type config_pool: ABCSLProcessorPool | None :return: 返回当前实例便于链式调用 :rtype: Self .. versionchanged:: 0.3.0 返回当前实例便于链式调用 .. py:method:: 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 保存处理器 :param processor_pool: 配置池 :type processor_pool: ABCSLProcessorPool :param config_file: 待保存配置 :type config_file: ABCConfigFile :param root_path: 保存的根目录 :type root_path: str :param namespace: 配置的命名空间 :type namespace: str :param file_name: 配置文件名 :type file_name: str :raise FailedProcessConfigFileError: 处理配置文件失败 .. versionchanged:: 0.2.0 添加参数 ``processor_pool`` .. py:method:: 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 保存指定命名空间的配置 :param config_pool: 配置池 :type config_pool: ABCConfigPool :param config_file: 配置文件 :type config_file: ABCConfigFile :param namespace: 命名空间 :type namespace: str :param file_name: 文件名 :type file_name: str .. py:attribute:: __slots__ :value: () .. py:attribute:: _cleanup_registry :type: bool :value: True 自动清理为了传递SL处理所加入配置池的配置文件 .. py:attribute:: _reg_alias :type: str | None :value: None .. py:attribute:: create_dir :value: True .. py:attribute:: meta_file :value: '__meta__' .. py:attribute:: meta_parser :type: config.abc.ABCMetaParser[Any, config.basic.component.ComponentMeta[Any]] :value: None .. py:property:: processor_reg_name :type: str SL处理器的默认注册名 .. py:attribute:: raises .. py:property:: reg_alias :type: str | None 处理器的别名 .. py:property:: reg_name :type: str 处理器的注册名 .. py:attribute:: supported_file_classes :return: 支持的配置文件类 .. versionadded:: 0.2.0 .. py:property:: supported_file_patterns :type: tuple[str, Ellipsis] :return: 支持的文件名匹配 .. versionchanged:: 0.2.0 重命名 ``file_ext`` 为 ``supported_file_patterns``