💥 remove deprecated nonebot.plugins toml table (#1151)

Feature: 移除过时的 `nonebot.plugins` toml 配置
This commit is contained in:
Ju4tCode
2022-08-16 10:03:37 +08:00
committed by GitHub
parent cdc507bab9
commit 898c29d7ee
8 changed files with 42 additions and 10 deletions

View File

@ -74,6 +74,8 @@ def load_from_json(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
"""
with open(file_path, "r", encoding=encoding) as f:
data = json.load(f)
if not isinstance(data, dict):
raise TypeError("json file must contains a dict!")
plugins = data.get("plugins")
plugin_dirs = data.get("plugin_dirs")
assert isinstance(plugins, list), "plugins must be a list of plugin name"
@ -103,15 +105,10 @@ def load_from_toml(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
data = tomlkit.parse(f.read()) # type: ignore
nonebot_data = data.get("tool", {}).get("nonebot")
if not nonebot_data:
nonebot_data = data.get("nonebot", {}).get("plugins")
if nonebot_data:
warnings.warn(
"[nonebot.plugins] table is deprecated. Use [tool.nonebot] instead.",
DeprecationWarning,
)
else:
raise ValueError("Cannot find '[tool.nonebot]' in given toml file!")
if nonebot_data is None:
raise ValueError("Cannot find '[tool.nonebot]' in given toml file!")
if not isinstance(nonebot_data, dict):
raise TypeError("'[tool.nonebot]' must be a Table!")
plugins = nonebot_data.get("plugins", [])
plugin_dirs = nonebot_data.get("plugin_dirs", [])
assert isinstance(plugins, list), "plugins must be a list of plugin name"