Skip to content

Commit

Permalink
fix(plugin_test): 适配最新dev
Browse files Browse the repository at this point in the history
  • Loading branch information
AkashiCoin committed Sep 1, 2024
1 parent 7b88006 commit ecfec02
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/utils/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ def get_session(

RUNNER_SCRIPT = """import json
import os
import json
import asyncio
from pathlib import Path
from nonebot import init, load_plugin, logger, require, load_plugins
from pydantic import BaseModel
from nonebot.adapters.onebot.v11 import Adapter as OneBotV11Adapter
from nonebot import init, logger, get_driver, load_plugin, load_plugins
class SetEncoder(json.JSONEncoder):
Expand All @@ -123,14 +125,14 @@ def default(self, obj):
init()
driver = get_driver()
driver.register_adapter(OneBotV11Adapter)
load_plugins("zhenxun/builtin_plugins")
from zhenxun.builtin_plugins.plugin_store.data_source import ShopManage, download_file
from zhenxun.builtin_plugins.plugin_store.data_source import ShopManage
url_path = ShopManage.get_url_path("{module_path}", {is_dir})
if not url_path:
logger.error("插件下载地址构建失败...")
exit(1)
asyncio.run(download_file("{github_download_url}".format(url_path), True, "{github_download_url}".split("/contents/")[0] + "/contents/"))
asyncio.run(
ShopManage.install_plugin_with_repo("{github_url}", "{module_path}", {is_dir}, True)
)
plugin = load_plugin(Path(__file__).parent / "zhenxun"/ "plugins" / "{module_name}")
if not plugin:
Expand Down Expand Up @@ -342,8 +344,8 @@ async def run_poetry_project(self) -> None:
f.write("ENVIRONMENT=dev")
# 如果提供了插件配置项,则写入配置文件
if self.config is not None:
with open(self.path / ".env.prod", "w", encoding="utf8") as f:
f.write(self.config)
with open(self.path / ".env.dev", "a+", encoding="utf8") as f:
f.write("\n" + self.config)

with open(self.path / "fake.py", "w", encoding="utf8") as f:
f.write(FAKE_SCRIPT)
Expand All @@ -354,7 +356,6 @@ async def run_poetry_project(self) -> None:
module_name=self.module_name,
module_path=self.module_path,
github_url=self.github_url,
github_download_url=self.get_github_download_url(),
is_dir=self.is_dir,
deps="\n".join([f"require('{i}')" for i in self._deps]),
)
Expand Down Expand Up @@ -388,12 +389,6 @@ async def run_poetry_project(self) -> None:
for i in _err:
self._log_output(f" {i}")

def get_github_download_url(self) -> str:
username, repo = re.match(
r"https://github.com/(.+)/(.+)(?:\.git)?", self.github_url
).groups()
return f"https://api.github.com/repos/{username}/{repo}/contents/{{}}?ref=main"

def _log_output(self, output: str) -> None:
"""记录输出,同时打印到控制台"""
print(output)
Expand Down

0 comments on commit ecfec02

Please sign in to comment.