diff options
| author | 2023-08-13 12:28:01 +0800 | |
|---|---|---|
| committer | 2023-08-13 12:28:01 +0800 | |
| commit | 697e9157669e467f41c5cd4b542aee861b320712 (patch) | |
| tree | 5e19c64615e5ae76a4dea5adecf2dffdb0f315b1 /HydroRollCore/config.py | |
| parent | 72fbe4b835ea6cf5664e3ade112fd47e33fde880 (diff) | |
| download | infini-697e9157669e467f41c5cd4b542aee861b320712.tar.gz infini-697e9157669e467f41c5cd4b542aee861b320712.zip | |
refactor: brandly new edition
Diffstat (limited to 'HydroRollCore/config.py')
| -rw-r--r-- | HydroRollCore/config.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/HydroRollCore/config.py b/HydroRollCore/config.py index e69de29b..4bee29df 100644 --- a/HydroRollCore/config.py +++ b/HydroRollCore/config.py @@ -0,0 +1,76 @@ +"""HydroRollCore 配置。 + +HydroRollCore 使用 [pydantic](https://pydantic-docs.helpmanual.io/) 来读取配置。 +""" +from typing import Set, Union + +from pydantic import Extra, Field, BaseModel, DirectoryPath + +__all__ = [ + "ConfigModel", + "LogConfig", + "CoreConfig", + "RuleConfig", + "MainConfig", +] + + +class ConfigModel(BaseModel): + """HydroRollCore 配置模型。 + + Attributes: + __config_name__: 配置名称。 + """ + + __config_name__: str + + class Config: + extra = Extra.allow + + +class LogConfig(ConfigModel): + """HydroRollCore 日志相关设置。 + + Attributes: + level: 日志级别。 + verbose_exception: 详细的异常记录,设置为 True 时会在日志中添加异常的 Traceback。 + """ + + level: Union[str, int] = "DEBUG" + verbose_exception: bool = False + + +class CoreConfig(ConfigModel): + """Core 配置。 + + Attributes: + rules: 将被加载的规则书列表,将被 `Core` 类的 `load_rules()` 方法加载。 + rule_dirs: 将被加载的规则书目录列表,将被 `Core` 类的 `load_rules_from_dirs()` 方法加载。 + log: HydroRollCore 日志相关设置。 + """ + + rules: Set[str] = Field(default_factory=set) + rule_dirs: Set[DirectoryPath] = Field(default_factory=set) + log: LogConfig = LogConfig() # type: ignore + + +class RuleConfig(ConfigModel): + """规则书配置。""" + + +class DebugConfig(ConfigModel): + """是否打印事件配置。""" + + +class MainConfig(ConfigModel): + """HydroRollCore 配置。 + + Attributes: + core: HydroRollCore 的主要配置。 + """ + + core: CoreConfig = CoreConfig() # type: ignore + rule: RuleConfig = RuleConfig() # type: ignore + + class Config: + extra = Extra.allow
\ No newline at end of file |
