Repository navigation
Description
Problem to solve / 要解决的问题
A toolchain installation is refused when its program is a symbolic link out of its home. Core's installation check (checked_installation in rust/crates/toolchain/src/query.rs) requires the canonical executable to stay inside the canonical home, and refuses everything else with unsafePath ("The executable escapes its installation or enters the workspace"). Two common kinds of Python install fail this check:
- Virtual environments outside the workspace.
python -m venv,uv venvand virtualenv make these environments, and virtualenv is what Poetry, Pipenv and virtualenvwrapper use. An environment keeps its ownpyvenv.cfgand packages, but on macOS and Linux itsbin/python3links to the base interpreter outside the environment. - Homebrew Python.
libexec/bin/python3inpython@3.xlinks to../../Frameworks/Python.framework/Versions/3.x/bin/python3.x, outsidelibexec. The framework'sbinholds onlypython3.x, so no layout of the tool definition reaches a real file inside a home.
Verified with the Python Support plugin on desktop main 6088516 (Core dcb3d77), macOS arm64:
- Pin on the Toolchains page: after a project pins an environment made by
python3 -m venvoutside the project, the Python build model fails withtoolchain python is unavailable: unsafePath. The project then has no Python run entries, so the toolbar reports that the current file has nothing to run. Pinning Homebrew's/opt/homebrew/opt/python@3.14/libexecfails the same way. - Discovery: the definition's Homebrew rule finds
/opt/homebrew/Cellar/python@3.14/<version>/libexec, and Core skips it withunsafePath, so Homebrew Python never appears as an installation. VIRTUAL_ENV: the plugin declareshomeVariable: VIRTUAL_ENV. WithVIRTUAL_ENVpointing at an environment outside the workspace and no pin, resolution skips it and selects the highest installed release (a uv-managed 3.13, not the environment).
These work today: a project .venv, base interpreters from uv, pyenv and python.org, and conda environments. Their programs are real files inside their homes. A project .venv works because the contract already lets a project environment's leaf executable link outside the workspace (projectKind: "environment" in the toolchain contract README). Windows environments start from Scripts\python.exe, which is not a link; Windows was not tested.
Impact:
- Poetry, Pipenv and virtualenvwrapper create environments outside the project by default. Users of these tools cannot pick their environment for analysis, run, test or debug.
- Homebrew is the most common way to install Python on macOS, and its Python cannot be used at all.
- Python Support keeps a plugin setting that overrides the interpreter, but it applies to runs and pytest only; Pyrefly and debugging use the interpreter the Toolchains page resolves. These users still cannot use such an interpreter for analysis or debugging.
- The interpreter dropdown planned for the plugin settings ([Feature] 插件设置区域的工具行可在原处选择工具链安装(类似 PyCharm 解释器下拉框),选中值进设置窗口草稿 #2311) needs these installations as choices too.
工具链安装里的程序是指向安装目录外的符号链接时,这个安装会被拒绝。Core 的安装检查(rust/crates/toolchain/src/query.rs 的 checked_installation)要求可执行文件解析后的路径仍在安装目录内,否则一律以 unsafePath 拒绝(“The executable escapes its installation or enters the workspace”)。两类常见的 Python 安装过不了这个检查:
- 工作区外的虚拟环境。 这类环境由
python -m venv、uv venv和 virtualenv 建立;Poetry、Pipenv、virtualenvwrapper 用的都是 virtualenv。环境有自己的pyvenv.cfg和包,但在 macOS 和 Linux 上,环境里的bin/python3是指向基础解释器的链接,指到了环境目录外面。 - Homebrew 的 Python。
python@3.x的libexec/bin/python3链接到../../Frameworks/Python.framework/Versions/3.x/bin/python3.x,在libexec外面。framework 的bin里只有python3.x,所以工具定义的任何布局都找不到安装目录内的真实文件。
在桌面端 main 6088516(Core dcb3d77)、macOS arm64 上用 Python Support 插件验证:
- 在工具链页固定: 为项目固定一个在项目外用
python3 -m venv建的环境后,Python 构建模型加载失败,报toolchain python is unavailable: unsafePath。项目里没有 Python 运行入口,工具栏提示当前文件没有可运行的入口。固定 Homebrew 的/opt/homebrew/opt/python@3.14/libexec也是同样的结果。 - 发现规则: 工具定义的 Homebrew 规则能找到
/opt/homebrew/Cellar/python@3.14/<版本>/libexec,但 Core 以unsafePath跳过它,所以 Homebrew 的 Python 从不出现在安装列表里。 VIRTUAL_ENV: 插件声明了homeVariable: VIRTUAL_ENV。VIRTUAL_ENV指向工作区外的环境、且没有固定时,解析跳过它,选中了已安装的最高版本(uv 管理的 3.13),而不是这个环境。
目前可以用的有:项目里的 .venv,uv、pyenv、python.org 装的基础解释器,以及 conda 环境。它们的程序都是安装目录里的真实文件。项目 .venv 可以用,是因为契约已经允许项目环境的最末一级可执行文件链接到工作区外(工具链契约 README 里 projectKind: "environment" 的规则)。Windows 上的环境从 Scripts\python.exe 启动,它不是链接;Windows 没有测试。
影响:
- Poetry、Pipenv、virtualenvwrapper 默认把环境建在项目外。这些工具的用户无法为分析、运行、测试和调试选择自己的环境。
- Homebrew 是 macOS 上最常见的 Python 安装方式,它的 Python 完全用不了。
- Python Support 保留了覆盖解释器的插件设置,但它只作用于运行和 pytest;Pyrefly 和调试使用工具链页解析出的解释器。所以这类解释器仍不能用于分析和调试。
- 插件设置里计划的解释器下拉框([Feature] 插件设置区域的工具行可在原处选择工具链安装(类似 PyCharm 解释器下拉框),选中值进设置窗口草稿 #2311)也需要把这类安装列为选项。
Proposed solution / 建议方案
-
Let a tool definition allow its program to link outside the home, as an optional field within the current toolchain capability version (an addition within version 0, with no version bump). Definitions that omit the field keep today's check.
-
For such a definition, apply the rule that project environments already follow to every installation: pins,
homeVariable, discovery and provider reports.- The home and every parent directory between the home and the layout path (such as
bin) must canonically stay inside the home. - The leaf executable may be a single-hop or multi-hop link to a regular executable file outside the home.
- Neither the home nor the canonical target may lie in a workspace. A program inside a workspace still needs the explicit action that project code needs today.
- The home and every parent directory between the home and the layout path (such as
-
Probe and start such an installation from its layout path (
<home>/bin/python3), never from the canonical target, and keep home exports such asVIRTUAL_ENVon the home. Python findspyvenv.cfgfrom the path it was started with, so starting the base interpreter would drop the environment's packages. -
Add Core vectors for: an environment that links outside (accepted), a Homebrew-style home whose program links to a sibling directory (accepted), a link whose target is in the workspace (refused), a home whose
bindirectory links outside (refused), and a definition without the field whose program links outside (still refused). -
Document the field in the toolchain contract README, record it in the protocol changelog, and pin desktop to the Core commit that has it.
-
工具定义可以声明允许程序链接到安装目录外,作为现有工具链能力版本内的可选字段(版本 0 内的补充,不升版本号)。不写这个字段的工具定义保持现在的检查。
-
声明了这个字段的工具定义,所有安装都按项目环境现有的规则检查,包括固定、
homeVariable、发现规则和提供者报告:- 安装目录,以及安装目录到布局路径之间的各级父目录(例如
bin),解析后都必须在安装目录内; - 最末一级可执行文件可以经过一次或多次链接,指向安装目录外的普通可执行文件;
- 安装目录和解析后的目标都不能在工作区内。工作区内的程序仍然需要现在项目代码所需的明确操作。
- 安装目录,以及安装目录到布局路径之间的各级父目录(例如
-
这类安装从布局路径(
<home>/bin/python3)探测和启动,不从解析后的目标启动;VIRTUAL_ENV等安装目录导出仍指向安装目录。Python 按启动时的路径找pyvenv.cfg,从基础解释器启动就会丢掉环境里的包。 -
Core 补测试向量:链接到外部的环境(接受)、程序链接到同级目录的 Homebrew 式安装(接受)、目标在工作区内的链接(拒绝)、
bin目录本身链接到外部的安装(拒绝)、没有声明字段但程序链接到外部的工具定义(仍拒绝)。 -
在工具链契约 README 写明这个字段,登记协议更新记录,桌面端固定到包含它的 Core 提交。
Target platform / 目标平台
Cross-platform / 跨平台
Area / 模块
Extensions / 扩展
Priority / 优先级
P1 / 尽快处理:使用体验大幅下降,但通常仍可继续使用
Alternatives considered / 已考虑的替代方案
-
Accept only homes that contain a marker file such as
pyvenv.cfg. This covers virtual environments but not Homebrew Python, which has no marker. The marker could still be added later as a narrower rule. -
Rely on the plugin setting that overrides the interpreter. Python Support keeps it, but it applies to runs and pytest only while Pyrefly and debugging use the toolchain, so analysis and runs can use different interpreters, and it duplicates the Toolchains page.
-
Ask users to create environments with
--copies. Poetry, Pipenv and uv choose how they create environments, copies break when the base interpreter is upgraded, and Homebrew Python has no such option. -
Drop the containment check for every installation. The check keeps an installation from starting a program elsewhere, such as in the workspace. Only definitions that declare the field need the exception, and the workspace check stays.
-
Workaround until this lands: create the environment inside the project as
.venv, or pin a base interpreter from uv, pyenv or python.org (without the environment's packages). -
只接受目录里有标记文件(例如
pyvenv.cfg)的安装。 这样能覆盖虚拟环境,但覆盖不了没有标记的 Homebrew Python。标记规则以后仍然可以作为更窄的规则加上。 -
只靠覆盖解释器的插件设置。 Python Support 保留了这个设置,但它只作用于运行和 pytest,Pyrefly 和调试仍用工具链,所以分析和运行可能用不同的解释器,也和工具链页重复。
-
让用户用
--copies建环境。 Poetry、Pipenv、uv 自己决定怎么建环境;复制出来的解释器在基础解释器升级后会失效;Homebrew Python 也没有这个选项。 -
对所有安装去掉包含检查。 这个检查防止安装去启动别处(例如工作区里)的程序。只有声明了字段的工具定义需要例外,工作区检查保留。
-
在此之前的临时办法: 把环境建在项目里的
.venv,或者固定 uv、pyenv、python.org 装的基础解释器(没有环境里的包)。
Additional context / 补充信息
-
Related: [Feature] Python 插件 lithe-plugin-python 设计:pyrefly 代码智能、uv/conda 解释器、运行、pytest 与 debugpy 调试,三端统一打包 #2122 (Python plugin design), [Feature] 插件设置区域的工具行可在原处选择工具链安装(类似 PyCharm 解释器下拉框),选中值进设置窗口草稿 #2311 (tool row picker in plugin settings).
-
Implementation: feat(toolchain): 工具定义可用 executableLinksOutsideHome 接受链接到主目录外的程序 Lithe-IDEA/Lithe-core-rust#177 (the
executableLinksOutsideHomefield and its checks in Core) and feat(desktop): 工具链接受链接到主目录外的环境程序,宿主沿布局路径观测各级目录(#2316) #2321 (desktop observes every directory on the layout path and pins that Core commit). -
The Python plugin's host end-to-end test that pins an interpreter pins a real installation (
PYTEST_PYTHON, for example one fromactions/setup-pythonoruv python install), because a pinned environment or Homebrew Python is refused today. -
The plugin keeps its Homebrew discovery rule, so Homebrew Python appears once Core accepts it.
-
相关:[Feature] Python 插件 lithe-plugin-python 设计:pyrefly 代码智能、uv/conda 解释器、运行、pytest 与 debugpy 调试,三端统一打包 #2122(Python 插件设计)、[Feature] 插件设置区域的工具行可在原处选择工具链安装(类似 PyCharm 解释器下拉框),选中值进设置窗口草稿 #2311(插件设置里的工具行选择器)。
-
实现:feat(toolchain): 工具定义可用 executableLinksOutsideHome 接受链接到主目录外的程序 Lithe-IDEA/Lithe-core-rust#177(Core 的
executableLinksOutsideHome字段和检查)、feat(desktop): 工具链接受链接到主目录外的环境程序,宿主沿布局路径观测各级目录(#2316) #2321(桌面端沿布局路径观测各级目录,并固定到该 Core 提交)。 -
Python 插件的宿主端到端测试里,固定解释器的用例固定的是一个真实安装(
PYTEST_PYTHON,例如actions/setup-python或uv python install装的),因为固定环境或 Homebrew Python 目前会被拒绝。 -
插件保留了 Homebrew 的发现规则,Core 接受之后 Homebrew Python 就会出现在列表里。
Checklist / 提交前检查
- I searched existing issues for duplicates. / 我已搜索现有 Issue,确认没有重复建议。
Activity
feat(toolchain): 工具定义可用 executableLinksOutsideHome 接受链接到主目录外的程序 (#177)
feat(desktop): 工具链接受链接到主目录外的环境程序,宿主沿布局路径观测各级目录(#2316) (#2321)