Skip to content

Commit a70cde9

Browse files
authored
Merge pull request #1 from Lithe-IDEA/feat/2122-m3-backend-pytest
feat(python): 接入 Pyrefly 解释器选择和 pytest 动态测试树
2 parents 8728b7a + c4dbabc commit a70cde9

17 files changed

Lines changed: 4862 additions & 272 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ jobs:
6868
- uses: actions/setup-python@v5
6969
with:
7070
python-version: "3.12"
71+
- name: Install pytest for live test-discovery and execution checks
72+
run: python -m pip install --disable-pip-version-check pytest
7173
- uses: actions/download-artifact@v4
7274
with:
7375
name: python-support-archives

‎README.md‎

Lines changed: 49 additions & 45 deletions
Large diffs are not rendered by default.

‎docs/feature-matrix.md‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
# Python Support 功能矩阵(Feature Matrix)
22

3-
本文档维护 `io.github.lithe-idea.python-support` 插件在 6 个目标发布平台上的实现与真实执行验证状态(插件功能矩阵与测试证据仅在本插件仓库维护,不进入宿主仓库)。
3+
本文档维护 `io.github.lithe-idea.python-support`(`v0.2.0`)插件在 6 个目标发布平台上的实现与真实执行验证状态(插件功能矩阵与测试证据仅在本插件仓库维护,不进入宿主仓库)。
44

55
## 状态定义
66

77
- `✅ 已验证`:已在目标平台实机完成打包安装、真实上游二进制/运行时进程执行及宿主端到端测试验证。
8-
- `⏳ 待实机验证(pending)`:已在 `plugin.json`、脚本与对应平台归档(`dist/python-support-0.1.0-<platform>.zip`)中完成实现,并通过归档路径/大小写安全检查、Lithe Store 规则校验以及 Unix/Windows 双清单真实 Core `ValidatePluginManifest` 契约校验;但尚未在对应 OS/架构实机或 CI runner 上执行原生子进程工作流,严禁在未实跑前标为已验证。
9-
- `🚧 规划中(M3)`:归属后续 M3 插件后端进程版本。
8+
- `⏳ 待实机验证(pending)`:已在 `plugin.json`、脚本与对应平台归档(`dist/python-support-0.2.0-<platform>.zip`)中完成实现,并通过归档路径/大小写安全检查、Lithe Store 规则校验以及 Unix/Windows 双清单真实 Core `ValidatePluginManifest` 契约校验;但尚未在对应 OS/架构实机或 CI runner 上执行原生子进程工作流,严禁在未实跑前标为已验证。
9+
- `🚧 待宿主开放(blocked on host capability)`:插件端协议与代码已完整实现并通过真实 Core 解码验证,待桌面宿主开放对应能力版本后启用清单声明。
1010

1111
## 跨平台能力与验证矩阵
1212

1313
| 能力域 | 功能项 | `darwin-arm64` | `darwin-x64` | `windows-x64` / `windows-arm64` | `linux-x64` / `linux-arm64` | 最近实机验证 | 实现与测试证据路径(本仓库) |
1414
| --- | --- | --- | --- | --- | --- | --- | --- |
15-
| 语言基础 (`languages`) | `.py` / `.pyi` / `.pyw` 识别、`#` 行注释、括号/引号配对、项目标记与 `.venv` / `venv` 依赖目录 | ✅ 已验证 | ⏳ pending(归档与清单已校验) | ⏳ pending(归档与 Windows 清单已校验) | ⏳ pending(归档与清单已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
16-
| 语言服务器 (`languageServers`) | 内置打包 `pyrefly` `1.4.1`(`bin/pyrefly` / `bin/pyrefly.exe`、`lsp`、`--version`、`workspaceConfiguration`、`indexingExclusions`,保留 `.venv` 原生自动发现) | ✅ 已验证 | ⏳ pending(`macos-x86_64` 二进制已打包校验) | ⏳ pending(`bin/pyrefly.exe` 已打包与契约校验) | ⏳ pending(`musl` 二进制已打包校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`<br>`vendor-lock.json`<br>`scripts/package.mjs`<br>`scripts/package/archives.test.mjs`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
17-
| 工具链与虚拟环境 (`toolDefinitions`) | `python` 4 层解析:项目绑定 → `.venv` / `venv`(受工作区信任门控,保留字面软链路径)→ 全局设置 → `VIRTUAL_ENV` + `PATH` → 16 条跨平台自动发现规则 | ✅ 已验证 | ⏳ pending(清单与 Core 规则已校验) | ⏳ pending(`Scripts/python.exe` / `python.exe` 布局与发现规则已通过 Core 校验) | ⏳ pending(清单与 Core 规则已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
18-
| 构建模型与运行 (`buildSystems: python`) | `scripts/build_model.py`(`-I -B`,纯 AST + `tomllib` / `vendor/tomli` 零代码执行)静态发现 `[project.scripts]`、包 `__main__.py`、顶层 `__main__` 脚本、Django `manage.py`、FastAPI ASGI、Flask WSGI 并派生 `run` 配置 | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/scripts/build_model.py`<br>`io.github.lithe-idea.python-support/plugin.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
19-
| 任务与测试 (`buildSystems: python`) | `pip install -r requirements.txt`、`mypy`(含诊断 `lineMatcher`)、`pytest`(支持工作区/项目/目标及 `suite` / `case` 过滤,解析 `.pytest_cache/lithe-junit.xml`) | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
15+
| 语言基础 (`languages`) | `.py` / `.pyi` / `.pyw` 识别、`#` 行注释、括号/引号配对、项目标记与 `.venv` / `venv` / `.conda` 依赖目录 | ✅ 已验证 | ⏳ pending(归档与清单已校验) | ⏳ pending(归档与 Windows 清单已校验) | ⏳ pending(归档与清单已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
16+
| 插件后端与语言服务器启动解析 (`backend` + `languageServers`) | 纯 Python(`python -I -B`)stdio JSON-RPC 后端 `scripts/backend.py`(协商 `litheLogging` 0 与 `litheFunctions` 0);`pyrefly.resolveLaunch` 按 `platform.os` 返回包内 `bin/pyrefly`(Unix)或 `bin/pyrefly.exe`(Windows)与 `["lsp"]`,在宿主传入 `tools.python.executable` 时自动注入 `workspaceConfiguration.python.pythonPath`(支持项目外 conda / uv / pyenv 解释器),缺失或未信任项目环境时优雅省略 `pythonPath` 回退 `pyrefly 1.4.1` 原生 `.venv` 发现 | ✅ 已验证 | ⏳ pending(`macos-x86_64` 二进制与纯 Python 后端已打包校验) | ⏳ pending(`bin/pyrefly.exe` 平台分支已通过 Core `DecodePluginLanguageServerLaunch` 校验) | ⏳ pending(`musl` 二进制与纯 Python 后端已打包校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/scripts/lithe_rpc.py`<br>`io.github.lithe-idea.python-support/scripts/backend.py`<br>`io.github.lithe-idea.python-support/plugin.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
17+
| 工具链与环境自动发现 (`toolDefinitions`) | `python` 4 层解析:项目绑定 → `.venv` / `venv` / `.conda`(受工作区信任门控,保留字面软链路径)→ 全局设置 → `VIRTUAL_ENV` + `PATH` → 16 条跨平台自动发现规则(覆盖 `UV_PYTHON_INSTALL_DIR`、`XDG_DATA_HOME`、`PYENV_ROOT`、`CONDA_ENVS_PATH`、`CONDA_PREFIX`、`WORKON_HOME`、`LOCALAPPDATA`、`APPDATA`、Homebrew、Framework、`~/.pyenv`、`~/.local/share/uv`、`*conda*/envs/*`、`miniforge*/envs/*`) | ✅ 已验证 | ⏳ pending(清单与 Core 规则已校验) | ⏳ pending(`Scripts/python.exe` / `python.exe` 布局与环境变量发现规则已通过 Core 校验) | ⏳ pending(清单与 Core 规则已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
18+
| 构建模型与运行 (`buildSystems: python` + `provider`) | `scripts/build_provider.py`(`python -I -B`,`lithe/build/model`)复用 `scripts/build_model.py` 纯 AST + `tomllib` / `vendor/tomli` 静态提取 `[project.scripts]`、包 `__main__.py`、顶层 `__main__` 脚本、Django `manage.py`、FastAPI ASGI、Flask WSGI 并派生 7 类声明式 `run` 配置;支持损坏 `pyproject.toml` 降级与修复后恢复诊断,并在协商 `litheBuild` 1 时支持 `lithe/build/runEntrypoints` | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/scripts/build_model.py`<br>`io.github.lithe-idea.python-support/scripts/build_provider.py`<br>`io.github.lithe-idea.python-support/plugin.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
19+
| 动态 `pytest` 测试树与测试执行 (`litheTestDiscovery` + `junitXml`) | `lithe/build/discoverTests` 通过有界可取消 `pytest --collect-only` 收集函数、测试类方法与 `@pytest.mark.parametrize` 参数化用例(缓存写入 `${workspaceStateDir}`,按条数和 UTF-8 字节限制返回 `litheTestDiscovery` v0);`lithe/build/test` 支持精确 node ID 与 JUnit 类名重跑,单个用例须带套件、`lithe/build/progress` 流式输出及 `.pytest_cache/lithe-junit.xml` 解码;保留 `pip install -r requirements.txt` 与 `mypy` 任务 | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/scripts/build_provider.py`<br>`io.github.lithe-idea.python-support/plugin.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
2020
| 独立工具构建系统 (`uv` / `conda` / `ruff`) | `uv`(`sync` / `lock`)、`conda`(`env update --file environment.yml --prune`)、`ruff`(`check` 含 `lineMatcher` / `format`)按各自标记文件独立检测与规划 | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
2121
| 调试器 (`debugAdapters: debugpy`) | 内置打包 `debugpy` `1.8.22`(`stdio` DAP,`["-I", "-B"]` + `scripts/debugpy_adapter.py`、`--log-dir ${logDir}`、适配器与 `launch` 双重设置 `PYTHONDONTWRITEBYTECODE=1` 保持插件目录零写入、支持远程 `attach` + `pathMappings`) | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`<br>`io.github.lithe-idea.python-support/scripts/debugpy_adapter.py`<br>`vendor-lock.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
2222
| 终端输出跳转 (`outputLinkMatchers`) | Python Traceback `File "...", line N` 点击定位源码与行号 | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
2323
| 新建项目向导 (`projectGenerators`) | `python-project`:选择并固定项目级 `python` 工具链(`pinAs: "project"`),可选 `none` / `venv (.venv)` / `uv (.venv)` 与示例代码生成(Windows 自动将 `python3` 命令切换为 `python`) | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(Windows 清单 `python` 命令切换已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`<br>`io.github.lithe-idea.python-support/templates/python/`<br>`scripts/package/archives.test.mjs`<br>`e2e/host/desktop/internal/projectgen/python_integration_test.go` |
2424
| 国际化 (`l10n`) | 英文默认文案 + `l10n/zh-Hans.json` 简体中文完整设置与分组翻译 | ✅ 已验证 | ⏳ pending(归档与 Core `settingsState` 已校验) | ⏳ pending(归档与 Core `settingsState` 已校验) | ⏳ pending(归档与 Core `settingsState` 已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/l10n/zh-Hans.json`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
25-
| 插件后端高级能力(M3) | `pytest --collect-only` 原生测试树发现、依赖树视图、`pyproject.toml` 原生配置页编辑器、工具链后端深度枚举 | 🚧 规划中(M3) | 🚧 规划中(M3) | 🚧 规划中(M3) | 🚧 规划中(M3) | — | — |
25+
| 工具链 Provider 协议 (`litheToolchains` / `toolchains/query`) | `scripts/toolchain_provider.py` 与 `backend.py` 已完整实现 `toolchains/query`(解析 `~/.conda/environments.txt`、`CONDA_ENVS_PATH`、`UV_PYTHON_INSTALL_DIR`、`PYENV_ROOT`、Poetry/Pipenv 外部虚拟环境、`.python-version` 与 `pyproject.toml` `requires-python`,严格排除工作区内目录并通过真实 Core `toolchains.decodeReply` 校验);清单层待桌面宿主开放 `toolchainProviders` 后启用(见下方前置说明) | 🚧 待宿主开放 `toolchainProviders`(后端协议与 Core 解码已在 `darwin-arm64` 实测通过) | 🚧 待宿主开放 `toolchainProviders` | 🚧 待宿主开放 `toolchainProviders` | 🚧 待宿主开放 `toolchainProviders` | `2026-11-18`(协议与 Core 解码验证) | `io.github.lithe-idea.python-support/scripts/toolchain_provider.py`<br>`io.github.lithe-idea.python-support/scripts/backend.py`<br>`scripts/test.mjs`<br>`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` |
26+
27+
## `toolchainProviders` 宿主前置条件说明
28+
29+
1. **桌面宿主能力门禁**:`Lithe-core-rust` 已支持 `toolchainProviders: 0`(`litheToolchains` 的 `toolchains/query` 与 `toolchains.decodeReply`),但当前桌面宿主 `desktop/internal/pluginhost/pluginhost.go` 的 `Declared()` 尚未声明 `toolchainProviders`。若在 `plugin.json` 中直接写入 `"requires": {"toolchainProviders": 0}`,当前桌面宿主安装校验会拒绝安装整个插件。
30+
2. **自举约束**:Core 清单校验(`validate_packaged_provider_backend`)要求声明 `toolchainProviders` 的插件后端必须使用包内可执行文件(`packaged`)或包内自带运行时(`packagedRuntime`)自举,不能依赖所要发现的外部 `tool: "python"` 启动。
31+
3. **当前落地方案**:桌面宿主通过 `toolDefinitions` 中的 16 条声明式规则和新增的 `.conda` 项目环境候选发现解释器。独立协议测试协商 `experimental.litheToolchains` 并验证 `toolchains/query` 响应。正式接线仍需桌面宿主开放能力、清单声明及打包后端自举,当前安装包通过固定宿主校验。

0 commit comments

Comments
 (0)