Skip to content

Commit

Permalink
fix(plugin_test): 修复创建环境报错时无法匹配到版本号的问题 (#279)
Browse files Browse the repository at this point in the history
* fix(plugin_test): 修复创建环境报错时无法匹配到版本号的问题

* fix: 还有一种安装失败的情况

* fix: 仅以 plugin_test_version 为准
  • Loading branch information
he0119 authored Nov 20, 2024
1 parent 88b919a commit 5de390a
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 77 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/

## [Unreleased]

### Fixed

- 修复创建环境报错时无法匹配到版本号的问题

## [4.0.5] - 2024-11-20

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ asyncio_default_fixture_loop_scope = "session"
exclude_also = ["if TYPE_CHECKING:", "raise NotImplementedError"]

[tool.coverage.run]
omit = ["src/providers/docker_test/plugin_test.py", "*.jinja"]
omit = ["*.jinja"]

[tool.nonebot]
adapters = [{ name = "GitHub", module_name = "nonebot.adapters.github" }]
Expand Down
19 changes: 16 additions & 3 deletions src/providers/docker_test/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,20 @@ def extract_version(output: str, project_link: str) -> str | None:
return match.group(1).strip()

# 匹配版本解析失败的情况
# 目前有很多插件都把信息填错了,没有使用 - 而是使用了 _
project_link = project_link.replace("_", "-")
# poetry 会将插件名称变成小写的,所以匹配时忽略大小写
match = re.search(
rf"depends on {project_link} \(\^(\S+)\), version solving failed\.", output
rf"depends on {project_link} \(\^(\S+)\), version solving failed\.",
output,
re.IGNORECASE,
)
if match:
return match.group(1).strip()

# 插件安装失败的情况
match = re.search(
rf"Using version \^(\S+) for {project_link}",
output,
re.IGNORECASE,
)
if match:
return match.group(1).strip()
Expand Down Expand Up @@ -318,6 +328,9 @@ async def create_poetry_project(self):
self._log_output(f"项目 {self.project_link} 创建成功。")
self._std_output(stdout, "")
else:
# 创建失败时尝试从报错中获取插件版本号
self._version = extract_version(stdout + stderr, self.project_link)

self._log_output(f"项目 {self.project_link} 创建失败:")
self._std_output(stdout, stderr)

Expand Down
5 changes: 2 additions & 3 deletions src/providers/store_test/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from src.providers.validation.utils import get_author_name

from .utils import get_latest_version, get_upload_time
from .utils import get_upload_time


async def validate_plugin(
Expand All @@ -35,7 +35,6 @@ async def validate_plugin(
module_name = store_plugin.module_name

# 从 PyPI 获取信息
pypi_version = get_latest_version(project_link)
pypi_time = get_upload_time(project_link)

# 测试插件
Expand Down Expand Up @@ -78,6 +77,7 @@ async def validate_plugin(
raw_data["skip_test"] = should_skip
raw_data["load"] = plugin_test_load
raw_data["test_output"] = plugin_test_output
raw_data["version"] = plugin_test_version

# 使用最新的插件元数据更新插件信息
raw_data["metadata"] = bool(plugin_metadata)
Expand All @@ -93,7 +93,6 @@ async def validate_plugin(
raw_data["author"] = author_name

# 更新插件信息
raw_data["version"] = plugin_test_version or pypi_version
raw_data["time"] = pypi_time

# 验证插件信息
Expand Down
111 changes: 111 additions & 0 deletions tests/utils/docker_test/test_extract_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from pathlib import Path


def test_extract_version(tmp_path: Path):
"""poetry show 的输出"""
from src.providers.docker_test.plugin_test import extract_version

output = """
name : nonebot2
version : 2.0.1
description : An asynchronous python bot framework.
dependencies
- httpx >=0.20.0,<1.0.0
- loguru >=0.6.0,<1.0.0
- pydantic >=1.10.0,<2.0.0
- pygtrie >=2.4.1,<3.0.0
- tomli >=2.0.1,<3.0.0
- typing-extensions >=4.0.0,<5.0.0
- yarl >=1.7.2,<2.0.0
required by
- nonebot-adapter-github >=2.0.0-beta.5,<3.0.0
- nonebug >=2.0.0-rc.2,<3.0.0
"""

version = extract_version(output, "nonebot2")
assert version == "2.0.1"


def test_extract_version_resolve_failed(tmp_path: Path):
"""版本解析失败的情况"""
from src.providers.docker_test.plugin_test import extract_version

output = """
项目 ELF-RSS 创建失败:
Virtualenv
Python: 3.12.7
Implementation: CPython
Path: NA
Executable: NA
Base
Platform: linux
OS: posix
Python: 3.12.7
Path: /usr/local
Executable: /usr/local/bin/python3.12
Using version ^2.6.25 for elf-rss
Updating dependencies
Resolving dependencies...
Creating virtualenv elf-rss-elf-rss2 in /tmp/plugin_test/ELF-RSS-ELF_RSS2/.venv
The current project's supported Python range (>=3.12,<3.13) is not compatible with some of the required packages Python requirement:
- elf-rss requires Python <4.0.0,>=3.12.6, so it will not be satisfied for Python >=3.12,<3.12.6
Because no versions of elf-rss match >2.6.25,<3.0.0
and elf-rss (2.6.25) requires Python <4.0.0,>=3.12.6, elf-rss is forbidden.
So, because elf-rss-elf-rss2 depends on elf-rss (^2.6.25), version solving failed.
• Check your dependencies Python requirement: The Python requirement can be specified via the `python` or `markers` properties
For elf-rss, a possible solution would be to set the `python` property to ">=3.12.6,<3.13"
https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies,
https://python-poetry.org/docs/dependency-specification/#using-environment-markers
"""

version = extract_version(output, "ELF-RSS")

assert version == "2.6.25"

version = extract_version(output, "nonebot2")

assert version is None


def test_extract_version_install_failed(tmp_path: Path):
"""安装插件失败的情况"""
from src.providers.docker_test.plugin_test import extract_version

output = """
项目 nonebot-plugin-ncm 创建失败:
Virtualenv
Python: 3.12.7
Implementation: CPython
Path: NA
Executable: NA
Base
Platform: linux
OS: posix
Python: 3.12.7
Path: /usr/local
Executable: /usr/local/bin/python3.12
Using version ^1.6.16 for nonebot-plugin-ncm
Updating dependencies
Resolving dependencies...
Package operations: 32 installs, 0 updates, 0 removals
"""

version = extract_version(output, "nonebot-plugin-ncm")

assert version == "1.6.16"

version = extract_version(output, "nonebot2")

assert version is None
70 changes: 0 additions & 70 deletions tests/utils/store_test/test_extract_version.py

This file was deleted.

0 comments on commit 5de390a

Please sign in to comment.