⬇️ 更新文档样式
This commit is contained in:
@ -1,30 +1,22 @@
|
||||
---
|
||||
title: liteyuki.config
|
||||
order: 1
|
||||
icon: laptop-code
|
||||
category: API
|
||||
---
|
||||
|
||||
### ***def*** `flat_config(config: dict[str, Any]) -> dict[str, Any]`
|
||||
|
||||
扁平化配置文件
|
||||
### *func* `flat_config() -> dict[str, Any]`
|
||||
|
||||
|
||||
|
||||
**Description**: 扁平化配置文件
|
||||
|
||||
{a:{b:{c:1}}} -> {"a.b.c": 1}
|
||||
|
||||
Args:
|
||||
**Arguments**:
|
||||
> - config: 配置项目
|
||||
|
||||
config: 配置项目
|
||||
**Return**: 扁平化后的配置文件,但也包含原有的键值对
|
||||
|
||||
|
||||
|
||||
Returns:
|
||||
|
||||
扁平化后的配置文件,但也包含原有的键值对
|
||||
|
||||
<details>
|
||||
<summary>源代码</summary>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def flat_config(config: dict[str, Any]) -> dict[str, Any]:
|
||||
@ -47,69 +39,80 @@ def flat_config(config: dict[str, Any]) -> dict[str, Any]:
|
||||
```
|
||||
</details>
|
||||
|
||||
### ***def*** `load_from_yaml(file: str) -> dict[str, Any]`
|
||||
### *func* `load_from_yaml() -> dict[str, Any]`
|
||||
|
||||
|
||||
|
||||
**Description**: Load config from yaml file
|
||||
|
||||
Load config from yaml file
|
||||
|
||||
<details>
|
||||
<summary>源代码</summary>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def load_from_yaml(file: str) -> dict[str, Any]:
|
||||
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'))
|
||||
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 {})
|
||||
```
|
||||
</details>
|
||||
|
||||
### ***def*** `load_from_json(file: str) -> dict[str, Any]`
|
||||
### *func* `load_from_json() -> dict[str, Any]`
|
||||
|
||||
|
||||
|
||||
**Description**: Load config from json file
|
||||
|
||||
Load config from json file
|
||||
|
||||
<details>
|
||||
<summary>源代码</summary>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def load_from_json(file: str) -> dict[str, Any]:
|
||||
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'))
|
||||
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 {})
|
||||
```
|
||||
</details>
|
||||
|
||||
### ***def*** `load_from_toml(file: str) -> dict[str, Any]`
|
||||
### *func* `load_from_toml() -> dict[str, Any]`
|
||||
|
||||
|
||||
|
||||
**Description**: Load config from toml file
|
||||
|
||||
Load config from toml file
|
||||
|
||||
<details>
|
||||
<summary>源代码</summary>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def load_from_toml(file: str) -> dict[str, Any]:
|
||||
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'))
|
||||
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 {})
|
||||
```
|
||||
</details>
|
||||
|
||||
### ***def*** `load_from_files() -> dict[str, Any]`
|
||||
### *func* `load_from_files(*, no_warning: bool = False) -> dict[str, Any]`
|
||||
|
||||
从指定文件加载配置项,会自动识别文件格式
|
||||
|
||||
|
||||
**Description**: 从指定文件加载配置项,会自动识别文件格式
|
||||
默认执行扁平化选项
|
||||
|
||||
|
||||
<details>
|
||||
<summary>源代码</summary>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def load_from_files(*files: str, no_warning: bool=False) -> dict[str, Any]:
|
||||
@ -134,16 +137,17 @@ def load_from_files(*files: str, no_warning: bool=False) -> dict[str, Any]:
|
||||
```
|
||||
</details>
|
||||
|
||||
### ***def*** `load_configs_from_dirs() -> dict[str, Any]`
|
||||
### *func* `load_configs_from_dirs(*, no_waring: bool = False) -> dict[str, Any]`
|
||||
|
||||
从目录下加载配置文件,不递归
|
||||
|
||||
|
||||
**Description**: 从目录下加载配置文件,不递归
|
||||
按照读取文件的优先级反向覆盖
|
||||
|
||||
默认执行扁平化选项
|
||||
|
||||
|
||||
<details>
|
||||
<summary>源代码</summary>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def load_configs_from_dirs(*directories: str, no_waring: bool=False) -> dict[str, Any]:
|
||||
@ -165,16 +169,17 @@ def load_configs_from_dirs(*directories: str, no_waring: bool=False) -> dict[str
|
||||
```
|
||||
</details>
|
||||
|
||||
### ***def*** `load_config_in_default(no_waring: bool) -> dict[str, Any]`
|
||||
### *func* `load_config_in_default(no_waring: bool = False) -> dict[str, Any]`
|
||||
|
||||
从一个标准的轻雪项目加载配置文件
|
||||
|
||||
|
||||
**Description**: 从一个标准的轻雪项目加载配置文件
|
||||
项目目录下的config.*和config目录下的所有配置文件
|
||||
|
||||
项目目录下的配置文件优先
|
||||
|
||||
|
||||
<details>
|
||||
<summary>源代码</summary>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def load_config_in_default(no_waring: bool=False) -> dict[str, Any]:
|
||||
@ -189,43 +194,3 @@ def load_config_in_default(no_waring: bool=False) -> dict[str, Any]:
|
||||
```
|
||||
</details>
|
||||
|
||||
### ***class*** `SatoriNodeConfig(BaseModel)`
|
||||
|
||||
|
||||
|
||||
### ***class*** `SatoriConfig(BaseModel)`
|
||||
|
||||
|
||||
|
||||
### ***class*** `BasicConfig(BaseModel)`
|
||||
|
||||
|
||||
|
||||
### ***var*** `new_config = copy.deepcopy(config)`
|
||||
|
||||
|
||||
|
||||
### ***var*** `config = yaml.safe_load(open(file, 'r', encoding='utf-8'))`
|
||||
|
||||
|
||||
|
||||
### ***var*** `config = json.load(open(file, 'r', encoding='utf-8'))`
|
||||
|
||||
|
||||
|
||||
### ***var*** `config = toml.load(open(file, 'r', encoding='utf-8'))`
|
||||
|
||||
|
||||
|
||||
### ***var*** `config = {}`
|
||||
|
||||
|
||||
|
||||
### ***var*** `config = {}`
|
||||
|
||||
|
||||
|
||||
### ***var*** `config = load_configs_from_dirs('config', no_waring=no_waring)`
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user