mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-06-15 16:47:42 +00:00
🔊 add deprecation warning for toml load
This commit is contained in:
parent
57e826a835
commit
ea502c1fff
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import warnings
|
||||||
from typing import Set, Iterable, Optional
|
from typing import Set, Iterable, Optional
|
||||||
|
|
||||||
import tomlkit
|
import tomlkit
|
||||||
@ -113,9 +114,14 @@ def load_from_toml(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
|
|||||||
with open(file_path, "r", encoding=encoding) as f:
|
with open(file_path, "r", encoding=encoding) as f:
|
||||||
data = tomlkit.parse(f.read()) # type: ignore
|
data = tomlkit.parse(f.read()) # type: ignore
|
||||||
|
|
||||||
nonebot_data = data.get("tool", {}).get("nonebot") or data.get(
|
nonebot_data = data.get("tool", {}).get("nonebot")
|
||||||
"nonebot", {}).get("plugins")
|
|
||||||
if not nonebot_data:
|
if not nonebot_data:
|
||||||
|
nonebot_data = data.get("nonebot", {}).get("plugins")
|
||||||
|
if nonebot_data:
|
||||||
|
warnings.warn(
|
||||||
|
"[nonebot.plugins] table are now deprecated. Use [tool.nonebot] instead.",
|
||||||
|
DeprecationWarning)
|
||||||
|
else:
|
||||||
raise ValueError("Cannot find '[tool.nonebot]' in given toml file!")
|
raise ValueError("Cannot find '[tool.nonebot]' in given toml file!")
|
||||||
plugins = nonebot_data.get("plugins", [])
|
plugins = nonebot_data.get("plugins", [])
|
||||||
plugin_dirs = nonebot_data.get("plugin_dirs", [])
|
plugin_dirs = nonebot_data.get("plugin_dirs", [])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user