mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 09:05:04 +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.typing import Union, Optional, NoReturn
|
||||
|
||||
try:
|
||||
import nonebot_test
|
||||
except ImportError:
|
||||
nonebot_test = 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 = Driver(env, config)
|
||||
|
||||
# register build-in adapters
|
||||
_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,
|
||||
port: Optional[int] = None,
|
||||
|
@ -16,8 +16,9 @@ class BaseConfig(BaseSettings):
|
||||
|
||||
def _build_environ(
|
||||
self,
|
||||
_env_file: Union[Path, str,
|
||||
None] = None) -> Dict[str, Optional[str]]:
|
||||
_env_file: Union[Path, str, None] = None,
|
||||
_env_file_encoding: Optional[str] = None
|
||||
) -> Dict[str, Optional[str]]:
|
||||
"""
|
||||
Build environment variables suitable for passing to the Model.
|
||||
"""
|
||||
@ -28,13 +29,16 @@ class BaseConfig(BaseSettings):
|
||||
else:
|
||||
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_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:
|
||||
env_path = Path(env_file)
|
||||
if env_path.is_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}
|
||||
|
||||
for field in self.__fields__.values():
|
||||
|
@ -23,9 +23,9 @@ python = "^3.7"
|
||||
httpx = "^0.13.3"
|
||||
fastapi = "^0.58.1"
|
||||
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 }
|
||||
# nonebot-test = { version = "^0.1.0", optional = true }
|
||||
nonebot-test = { version = "^0.1.0", optional = true }
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
yapf = "^0.30.0"
|
||||
|
Loading…
Reference in New Issue
Block a user