diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e9be399..a7f92562 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 9da5b230..bdb19528 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }] diff --git a/src/providers/docker_test/plugin_test.py b/src/providers/docker_test/plugin_test.py index e8b1fdf3..99bb4f37 100644 --- a/src/providers/docker_test/plugin_test.py +++ b/src/providers/docker_test/plugin_test.py @@ -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() @@ -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) diff --git a/src/providers/store_test/validation.py b/src/providers/store_test/validation.py index 6b5c5e95..e089bdb5 100644 --- a/src/providers/store_test/validation.py +++ b/src/providers/store_test/validation.py @@ -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( @@ -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) # 测试插件 @@ -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) @@ -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 # 验证插件信息 diff --git a/tests/utils/docker_test/test_extract_version.py b/tests/utils/docker_test/test_extract_version.py new file mode 100644 index 00000000..cda2ae6e --- /dev/null +++ b/tests/utils/docker_test/test_extract_version.py @@ -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 diff --git a/tests/utils/store_test/test_extract_version.py b/tests/utils/store_test/test_extract_version.py deleted file mode 100644 index d090a707..00000000 --- a/tests/utils/store_test/test_extract_version.py +++ /dev/null @@ -1,70 +0,0 @@ -# from pathlib import Path - - -# def test_extract_version(tmp_path: Path): -# """poetry show 的输出""" -# from src.providers.store_test.validation import extract_version - -# with open(tmp_path / "output.txt", "w", encoding="utf-8") 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 docker_plugin_test import extract_version - -# with open(tmp_path / "output.txt", "w", encoding="utf-8") 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 "" - -# 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, "nonebot_plugin_mockingbird") - -# assert version == "0.2.1" - -# version = extract_version(tmp_path, "nonebot2") - -# assert version is None