Skip to content

Commit

Permalink
fix: 修复版本解析失败时无法匹配到插件版本的问题 (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 authored Sep 7, 2023
1 parent 2bfb8d2 commit 80b68ad
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 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

- 修复版本解析失败时无法匹配到插件版本的问题

## [3.0.5] - 2023-09-06

### Fixed
Expand Down
16 changes: 13 additions & 3 deletions src/utils/store_test/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ def extract_metadata(path: Path) -> Metadata | None:
return json.loads(match.group(1))


def extract_version(path: Path) -> str | None:
def extract_version(path: Path, project_link: str) -> str | None:
"""提取插件版本"""
with open(path / "output.txt", encoding="utf8") as f:
output = f.read()
match = re.search(r"version\s+:\s+(\S+)", strip_ansi(output))
output = strip_ansi(output)

# 匹配 poetry show 的输出
match = re.search(r"version\s+:\s+(\S+)", output)
if match:
return match.group(1).strip()

# 匹配版本解析失败的情况
match = re.search(
rf"depends on {project_link} \(\^(\S+)\), version solving failed\.", output
)
if match:
return match.group(1).strip()

Expand Down Expand Up @@ -97,7 +107,7 @@ async def validate_plugin(
plugin_test_result, plugin_test_output = await test.run()

metadata = extract_metadata(test.path)
test_version = extract_version(test.path)
test_version = extract_version(test.path, project_link)

# 测试并提取完数据后删除测试文件夹
shutil.rmtree(test.path)
Expand Down
66 changes: 66 additions & 0 deletions tests/utils/store_test/test_extract_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from pathlib import Path


def test_extract_version(tmp_path: Path):
"""poetry show 的输出"""
from src.utils.store_test.validation import extract_version

with open(tmp_path / "output.txt", "w", encoding="utf8") as f:
f.write(
"""
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(tmp_path, "nonebot2")
assert version == "2.0.1"


def test_extract_version_failed(tmp_path: Path):
"""版本解析失败的情况"""
from src.utils.store_test.validation import extract_version

with open(tmp_path / "output.txt", "w", encoding="utf8") as f:
f.write(
"""
项目 nonebot-plugin-mockingbird 创建失败:
Creating virtualenv nonebot-plugin-mockingbird-nonebot-plugin-mockingbird-test in /home/runner/work/registry/registry/plugin_test/nonebot-plugin-mockingbird-nonebot_plugin_mockingbird-test/.venv
The current project's Python requirement (>=3.10,<3.11) is not compatible with some of the required packages Python requirement:
- nonebot-plugin-mockingbird requires Python >=3.8,<3.10, so it will not be satisfied for Python >=3.10,<3.11
Because no versions of nonebot-plugin-mockingbird match >0.2.1,<0.3.0
and nonebot-plugin-mockingbird (0.2.1) requires Python >=3.8,<3.10, nonebot-plugin-mockingbird is forbidden.
So, because nonebot-plugin-mockingbird-nonebot-plugin-mockingbird-test depends on nonebot-plugin-mockingbird (^0.2.1), version solving failed.
• Check your dependencies Python requirement: The Python requirement can be specified via the `python` or `markers` properties
For nonebot-plugin-mockingbird, a possible solution would be to set the `python` property to "<empty>"
https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies,
https://python-poetry.org/docs/dependency-specification/#using-environment-markers
"""
)

version = extract_version(tmp_path, "nonebot-plugin-mockingbird")

assert version == "0.2.1"

version = extract_version(tmp_path, "nonebot2")

assert version is None

0 comments on commit 80b68ad

Please sign in to comment.