import{_ as a,o as t,c as o,a as n,b as s,d as p}from"./app-EhCe7g9m.js";const e={},i=n("h3",{id:"func-flat-config-dict-str-any",tabindex:"-1"},[n("a",{class:"header-anchor",href:"#func-flat-config-dict-str-any"},[n("span",null,[n("em",null,"func"),s(),n("code",null,"flat_config() -> dict[str, Any]")])])],-1),c=n("p",null,[n("strong",null,"说明"),s(": 扁平化配置文件")],-1),l=n("p",{"a.b.c:1":""},"{a:{b:{c:1}}} ->",-1),u=p(`

返回: 扁平化后的配置文件,但也包含原有的键值对

参数:

源代码
def flat_config(config: dict[str, Any]) -> dict[str, Any]:
    """
    扁平化配置文件

    {a:{b:{c:1}}} -> {"a.b.c": 1}
    Args:
        config: 配置项目

    Returns:
        扁平化后的配置文件,但也包含原有的键值对
    """
    new_config = copy.deepcopy(config)
    for (key, value) in config.items():
        if isinstance(value, dict):
            for (k, v) in flat_config(value).items():
                new_config[f'{key}.{k}'] = v
    return new_config

func load_from_yaml() -> dict[str, Any]

说明: Load config from yaml file

源代码
def load_from_yaml(file_: str) -> dict[str, Any]:
    """
    Load config from yaml file

    """
    logger.debug(f'Loading YAML config from {file_}')
    config = yaml.safe_load(open(file_, 'r', encoding='utf-8'))
    return flat_config(config if config is not None else {})

func load_from_json() -> dict[str, Any]

说明: Load config from json file

源代码
def load_from_json(file_: str) -> dict[str, Any]:
    """
    Load config from json file
    """
    logger.debug(f'Loading JSON config from {file_}')
    config = json.load(open(file_, 'r', encoding='utf-8'))
    return flat_config(config if config is not None else {})

func load_from_toml() -> dict[str, Any]

说明: Load config from toml file

源代码
def load_from_toml(file_: str) -> dict[str, Any]:
    """
    Load config from toml file
    """
    logger.debug(f'Loading TOML config from {file_}')
    config = toml.load(open(file_, 'r', encoding='utf-8'))
    return flat_config(config if config is not None else {})

func load_from_files(*, no_warning: bool = False) -> dict[str, Any]

说明: 从指定文件加载配置项,会自动识别文件格式 默认执行扁平化选项

源代码
def load_from_files(*files: str, no_warning: bool=False) -> dict[str, Any]:
    """
    从指定文件加载配置项,会自动识别文件格式
    默认执行扁平化选项
    """
    config = {}
    for file in files:
        if os.path.exists(file):
            if file.endswith(('.yaml', 'yml')):
                config.update(load_from_yaml(file))
            elif file.endswith('.json'):
                config.update(load_from_json(file))
            elif file.endswith('.toml'):
                config.update(load_from_toml(file))
            elif not no_warning:
                logger.warning(f'Unsupported config file format: {file}')
        elif not no_warning:
            logger.warning(f'Config file not found: {file}')
    return config

func load_configs_from_dirs(*, no_waring: bool = False) -> dict[str, Any]

说明: 从目录下加载配置文件,不递归 按照读取文件的优先级反向覆盖 默认执行扁平化选项

源代码
def load_configs_from_dirs(*directories: str, no_waring: bool=False) -> dict[str, Any]:
    """
    从目录下加载配置文件,不递归
    按照读取文件的优先级反向覆盖
    默认执行扁平化选项
    """
    config = {}
    for directory in directories:
        if not os.path.exists(directory):
            if not no_waring:
                logger.warning(f'Directory not found: {directory}')
            continue
        for file in os.listdir(directory):
            if file.endswith(_SUPPORTED_CONFIG_FORMATS):
                config.update(load_from_files(os.path.join(directory, file), no_warning=no_waring))
    return config

func load_config_in_default(no_waring: bool = False) -> dict[str, Any]

说明: 从一个标准的轻雪项目加载配置文件 项目目录下的config.*和config目录下的所有配置文件 项目目录下的配置文件优先

源代码
def load_config_in_default(no_waring: bool=False) -> dict[str, Any]:
    """
    从一个标准的轻雪项目加载配置文件
    项目目录下的config.*和config目录下的所有配置文件
    项目目录下的配置文件优先
    """
    config = load_configs_from_dirs('config', no_waring=no_waring)
    config.update(load_from_files('config.yaml', 'config.toml', 'config.json', 'config.yml', no_warning=no_waring))
    return config
`,22),r=[i,c,l,u];function d(k,f){return t(),o("div",null,r)}const m=a(e,[["render",d],["__file","config.html.vue"]]),v=JSON.parse('{"path":"/api/config.html","title":"liteyuki.config","lang":"zh-CN","frontmatter":{"title":"liteyuki.config","description":"func flat_config() -> dict[str, Any] 说明: 扁平化配置文件 {a:{b:{c:1}}} -> 返回: 扁平化后的配置文件,但也包含原有的键值对 参数: config: 配置项目 源代码 func load_from_yaml() -> dict[str, Any] 说明: Load config from yaml...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/api/config.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/api/config.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.config"}],["meta",{"property":"og:description","content":"func flat_config() -> dict[str, Any] 说明: 扁平化配置文件 {a:{b:{c:1}}} -> 返回: 扁平化后的配置文件,但也包含原有的键值对 参数: config: 配置项目 源代码 func load_from_yaml() -> dict[str, Any] 说明: Load config from yaml..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:locale:alternate","content":"en-US"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"liteyuki.config\\",\\"image\\":[\\"\\"],\\"dateModified\\":null,\\"author\\":[]}"]]},"headers":[{"level":3,"title":"func flat_config() -> dict[str, Any]","slug":"func-flat-config-dict-str-any","link":"#func-flat-config-dict-str-any","children":[]},{"level":3,"title":"func load_from_yaml() -> dict[str, Any]","slug":"func-load-from-yaml-dict-str-any","link":"#func-load-from-yaml-dict-str-any","children":[]},{"level":3,"title":"func load_from_json() -> dict[str, Any]","slug":"func-load-from-json-dict-str-any","link":"#func-load-from-json-dict-str-any","children":[]},{"level":3,"title":"func load_from_toml() -> dict[str, Any]","slug":"func-load-from-toml-dict-str-any","link":"#func-load-from-toml-dict-str-any","children":[]},{"level":3,"title":"func load_from_files(*, no_warning: bool = False) -> dict[str, Any]","slug":"func-load-from-files-no-warning-bool-false-dict-str-any","link":"#func-load-from-files-no-warning-bool-false-dict-str-any","children":[]},{"level":3,"title":"func load_configs_from_dirs(*, no_waring: bool = False) -> dict[str, Any]","slug":"func-load-configs-from-dirs-no-waring-bool-false-dict-str-any","link":"#func-load-configs-from-dirs-no-waring-bool-false-dict-str-any","children":[]},{"level":3,"title":"func load_config_in_default(no_waring: bool = False) -> dict[str, Any]","slug":"func-load-config-in-default-no-waring-bool-false-dict-str-any","link":"#func-load-config-in-default-no-waring-bool-false-dict-str-any","children":[]}],"git":{"createdTime":null,"updatedTime":null,"contributors":[]},"readingTime":{"minutes":2.4,"words":719},"filePathRelative":"api/config.md","autoDesc":true}');export{m as comp,v as data};