Skip to content

Commit

Permalink
feat: 使用 uv 来安装对应版本的 Python
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 committed Dec 8, 2024
1 parent 12b3adc commit 2d8485b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/providers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
# 商店测试镜像
# https://github.com/orgs/nonebot/packages/container/package/nonetest
DOCKER_IMAGES_VERSION = os.environ.get("DOCKER_IMAGES_VERSION") or "latest"
DOCKER_IMAGES = f"ghcr.io/nonebot/nonetest:{{}}-{DOCKER_IMAGES_VERSION}"
DOCKER_IMAGES = f"ghcr.io/nonebot/nonetest:{DOCKER_IMAGES_VERSION}"
5 changes: 3 additions & 2 deletions src/providers/docker_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,21 @@ async def run(self, version: str) -> DockerTestResult:
Returns:
DockerTestResult: 测试结果
"""
image_name = DOCKER_IMAGES.format(version)
# 连接 Docker 环境
client = docker.DockerClient(base_url="unix://var/run/docker.sock")

try:
# 运行 Docker 容器,捕获输出。 容器内运行的代码拥有超时设限,此处无需设置超时
output = client.containers.run(
image_name,
DOCKER_IMAGES,
environment={
"PROJECT_LINK": self.project_link,
"MODULE_NAME": self.module_name,
"PLUGIN_CONFIG": self.config,
# 插件测试需要用到的插件列表来验证插件依赖是否正确加载
"PLUGINS_URL": REGISTRY_PLUGINS_URL,
# 运行测试的 Python 版本
"PYTHON_VERSION": version,
},
detach=False,
remove=True,
Expand Down
14 changes: 11 additions & 3 deletions src/providers/docker_test/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,20 @@ def parse_requirements(requirements: str) -> dict[str, str]:

class PluginTest:
def __init__(
self, project_link: str, module_name: str, config: str | None = None
self,
python_version: str,
project_link: str,
module_name: str,
config: str | None = None,
) -> None:
"""插件测试构造函数
Args:
project_info (str): 项目信息,格式为 project_link:module_name
config (str | None, optional): 插件配置. 默认为 None.
"""
self.python_version = python_version

self.project_link = project_link
self.module_name = module_name
self.config = config
Expand Down Expand Up @@ -343,7 +349,7 @@ async def create_poetry_project(self):
self._test_dir.mkdir()

code, stdout, stderr = await self.command(
f"""poetry init -n && sed -i "s/\\^/~/g" pyproject.toml && poetry env info --ansi && poetry add {self.project_link}"""
f"""uv venv --python {self.python_version} && poetry init -n --python "~{self.python_version}" && poetry env info --ansi && poetry add {self.project_link}"""
)

self._create = code
Expand Down Expand Up @@ -481,11 +487,13 @@ def main():
MODULE_NAME 为插件的模块名
PLUGIN_CONFIG 即为该插件的配置
"""
python_version = os.environ.get("PYTHON_VERSION", "3.12")

project_link = os.environ.get("PROJECT_LINK", "")
module_name = os.environ.get("MODULE_NAME", "")
plugin_config = os.environ.get("PLUGIN_CONFIG", None)

plugin = PluginTest(project_link, module_name, plugin_config)
plugin = PluginTest(python_version, project_link, module_name, plugin_config)

asyncio.run(plugin.run())

Expand Down

0 comments on commit 2d8485b

Please sign in to comment.