Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/
### Fixed

- 修复插件测试获取到的插件元数据主页为空时报错的问题
- 使用规范化的名称匹配插件版本号

## [4.0.6] - 2024-11-20

Expand Down
18 changes: 9 additions & 9 deletions src/providers/docker_test/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def get_plugin_list() -> dict[str, str]:
return {plugin["project_link"]: plugin["module_name"] for plugin in plugins}


_canonicalize_regex = re.compile(r"[-_.]+")


def extract_version(output: str, project_link: str) -> str | None:
"""提取插件版本"""
output = strip_ansi(output)
Expand All @@ -170,22 +173,19 @@ def extract_version(output: str, project_link: str) -> str | None:
if match:
return match.group(1).strip()

# poetry 使用 packaging.utils 中的 canonicalize_name 规范化名称
# 在这里我们也需要规范化名称,以正确匹配版本号
project_link = _canonicalize_regex.sub("-", project_link).lower()

# 匹配版本解析失败的情况
# poetry 会将插件名称变成小写的,所以匹配时忽略大小写
match = re.search(
rf"depends on {project_link} \(\^(\S+)\), version solving failed\.",
output,
re.IGNORECASE,
rf"depends on {project_link} \(\^(\S+)\), version solving failed\.", output
)
if match:
return match.group(1).strip()

# 插件安装失败的情况
match = re.search(
rf"Using version \^(\S+) for {project_link}",
output,
re.IGNORECASE,
)
match = re.search(rf"Using version \^(\S+) for {project_link}", output)
if match:
return match.group(1).strip()

Expand Down
4 changes: 4 additions & 0 deletions tests/utils/docker_test/test_extract_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def test_extract_version_install_failed(tmp_path: Path):

assert version == "1.6.16"

version = extract_version(output, "nonebot_plugin_ncm")

assert version == "1.6.16"

version = extract_version(output, "nonebot2")

assert version is None
Loading