mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-02-18 00:30:13 +08:00
fix config and import nonebot-test
This commit is contained in:
parent
0eb5f51d2c
commit
04f4d5028e
@ -11,6 +11,11 @@ from nonebot.drivers import BaseDriver
|
|||||||
from nonebot.adapters.cqhttp import Bot as CQBot
|
from nonebot.adapters.cqhttp import Bot as CQBot
|
||||||
from nonebot.typing import Union, Optional, NoReturn
|
from nonebot.typing import Union, Optional, NoReturn
|
||||||
|
|
||||||
|
try:
|
||||||
|
import nonebot_test
|
||||||
|
except ImportError:
|
||||||
|
nonebot_test = None
|
||||||
|
|
||||||
_driver: Optional[BaseDriver] = None
|
_driver: Optional[BaseDriver] = None
|
||||||
|
|
||||||
|
|
||||||
@ -41,8 +46,13 @@ def init(*, _env_file: Optional[str] = None, **kwargs):
|
|||||||
Driver = getattr(importlib.import_module(config.driver), "Driver")
|
Driver = getattr(importlib.import_module(config.driver), "Driver")
|
||||||
_driver = Driver(env, config)
|
_driver = Driver(env, config)
|
||||||
|
|
||||||
|
# register build-in adapters
|
||||||
_driver.register_adapter("cqhttp", CQBot)
|
_driver.register_adapter("cqhttp", CQBot)
|
||||||
|
|
||||||
|
# load nonebot test frontend if debug
|
||||||
|
if config.debug and nonebot_test:
|
||||||
|
nonebot_test.init()
|
||||||
|
|
||||||
|
|
||||||
def run(host: Optional[IPv4Address] = None,
|
def run(host: Optional[IPv4Address] = None,
|
||||||
port: Optional[int] = None,
|
port: Optional[int] = None,
|
||||||
|
@ -16,8 +16,9 @@ class BaseConfig(BaseSettings):
|
|||||||
|
|
||||||
def _build_environ(
|
def _build_environ(
|
||||||
self,
|
self,
|
||||||
_env_file: Union[Path, str,
|
_env_file: Union[Path, str, None] = None,
|
||||||
None] = None) -> Dict[str, Optional[str]]:
|
_env_file_encoding: Optional[str] = None
|
||||||
|
) -> Dict[str, Optional[str]]:
|
||||||
"""
|
"""
|
||||||
Build environment variables suitable for passing to the Model.
|
Build environment variables suitable for passing to the Model.
|
||||||
"""
|
"""
|
||||||
@ -28,13 +29,16 @@ class BaseConfig(BaseSettings):
|
|||||||
else:
|
else:
|
||||||
env_vars = {k.lower(): v for k, v in os.environ.items()}
|
env_vars = {k.lower(): v for k, v in os.environ.items()}
|
||||||
|
|
||||||
|
env_file_vars: Dict[str, Optional[str]] = {}
|
||||||
env_file = _env_file if _env_file != env_file_sentinel else self.__config__.env_file
|
env_file = _env_file if _env_file != env_file_sentinel else self.__config__.env_file
|
||||||
env_file_vars = {}
|
env_file_encoding = _env_file_encoding if _env_file_encoding is not None else self.__config__.env_file_encoding
|
||||||
if env_file is not None:
|
if env_file is not None:
|
||||||
env_path = Path(env_file)
|
env_path = Path(env_file)
|
||||||
if env_path.is_file():
|
if env_path.is_file():
|
||||||
env_file_vars = read_env_file(
|
env_file_vars = read_env_file(
|
||||||
env_path, case_sensitive=self.__config__.case_sensitive)
|
env_path,
|
||||||
|
encoding=env_file_encoding,
|
||||||
|
case_sensitive=self.__config__.case_sensitive)
|
||||||
env_vars = {**env_file_vars, **env_vars}
|
env_vars = {**env_file_vars, **env_vars}
|
||||||
|
|
||||||
for field in self.__fields__.values():
|
for field in self.__fields__.values():
|
||||||
|
@ -23,9 +23,9 @@ python = "^3.7"
|
|||||||
httpx = "^0.13.3"
|
httpx = "^0.13.3"
|
||||||
fastapi = "^0.58.1"
|
fastapi = "^0.58.1"
|
||||||
uvicorn = "^0.11.5"
|
uvicorn = "^0.11.5"
|
||||||
pydantic = { extras = ["dotenv"], version = "^1.5.1" }
|
pydantic = { extras = ["dotenv"], version = "^1.6.1" }
|
||||||
apscheduler = { version = "^3.6.3", optional = true }
|
apscheduler = { version = "^3.6.3", optional = true }
|
||||||
# nonebot-test = { version = "^0.1.0", optional = true }
|
nonebot-test = { version = "^0.1.0", optional = true }
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
yapf = "^0.30.0"
|
yapf = "^0.30.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user