diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f3af1f..96ac166 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,8 +115,6 @@ jobs: path: dist - name: Install pytest for the host suite run: python -m pip install --disable-pip-version-check pytest - - name: Verify Python highlighting, run configurations, and dependencies on Lithe 0.8.9 - run: node scripts/e2e-host.mjs --ref 4d1b88f03f243356c855299464baa2647cc57226 --run '^TestPythonSupportPlugin(GrammarHighlighting|RunCurrentFile(InterpreterOverride|PinnedInterpreter)?|ManualRunAndDependencies)$' - name: Run the full Python host suite on the pinned desktop env: GOFLAGS: -tags=vivahead diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a8e2d50..abc7b5c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,7 +82,7 @@ jobs: - name: Publish GitHub Release env: GH_TOKEN: ${{ github.token }} - PRERELEASE_TAGS: v0.1.0 v0.1.1 + PRERELEASE_TAGS: v0.1.0 v0.1.1 v1.2.0 run: | release_flags=() installation='Lithe Store 会在收录后提供此版本。打开 设置 → 插件 → 插件市场,搜索 Python Support。' diff --git a/README.md b/README.md index 6add6c9..ce3f37b 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,10 @@ Pyrefly 和 debugpy 随插件包分发,Python 解释器、pytest、uv、conda > English: Python support for Lithe — Pyrefly code intelligence and type checking, run entries, a pytest test tree and > the installed-package tree in the build window, uv/conda/Ruff/mypy tasks, debugpy debugging, a Python project entry in > New Project, and previews on the settings pages. Pyrefly and debugpy ship in the plugin; the interpreter, pytest, uv, -> conda and Ruff stay your own. Pick the interpreter on Settings › Build, Execution, Deployment › Toolchains. +> conda and Ruff stay your own. Pick the interpreter from the drop-down at the top of Settings › Languages & Frameworks › Python. -> **兼容性**:需要 Lithe 桌面端 0.8.9 或更新版本;0.8.10 起还能按 shebang 识别没有后缀的 Python 脚本。 +> **兼容性**:1.2.0 需要 0.8.14 之后发布的 Lithe 桌面端(包含 [#2312](https://github.com/1lck/Lithe-IDEA/pull/2312) 和 +> [#2316](https://github.com/1lck/Lithe-IDEA/issues/2316) 的版本),旧版本不能安装,请继续用 1.1.0(支持 0.8.9 或更新版本)。 > 各版本的变化见 [docs/releases](docs/releases)。 ## 功能 @@ -18,7 +19,7 @@ Pyrefly 和 debugpy 随插件包分发,Python 解释器、pytest、uv、conda | 功能 | 说明 | | --- | --- | | 代码智能 | 补全、自动导入、跳转定义、悬停、类型诊断,由随包的 [Pyrefly](https://github.com/facebook/pyrefly) 1.4.1 提供 | -| 识别文件 | `.py`、`.pyi`、`.pyw`;0.8.10 起首行是 Python shebang 的无后缀脚本也按 Python 打开 | +| 识别文件 | `.py`、`.pyi`、`.pyw`;首行是 Python shebang 的无后缀脚本也按 Python 打开 | | 运行 | 工具栏「当前文件」运行带 `if __name__ == "__main__"` 的脚本和包里的 `__main__.py`;构建窗口列出 `[project.scripts]`、Django `manage.py`、FastAPI、Flask 等入口;「运行/调试配置 → + → Python」可以手动配置脚本或模块 | | 测试 | `pytest --collect-only` 收集函数、类方法、参数化用例和 doctest,组成测试树;可以运行整个套件或单个用例 | | 依赖 | 构建窗口的「依赖」列出所选解释器里已安装的包、版本和依赖关系,不需要 pip | @@ -26,7 +27,7 @@ Pyrefly 和 debugpy 随插件包分发,Python 解释器、pytest、uv、conda | 调试 | 随包的 debugpy 1.8.22,支持启动和按地址附加(`host`、`port`、`pathMappings`) | | 输出链接 | 终端和运行输出里 Traceback 的 `File "…", line N` 可以点击跳到源码 | | 新建项目 | 选解释器、选是否用 venv 或 uv 建 `.venv`、是否加示例代码;创建后项目固定使用所选解释器 | -| 工具链 | 找到项目的 `.venv` 和电脑上 uv、pyenv、conda、python.org 装的 Python,按 `.python-version` 和 `requires-python` 选版本,见下文“Python 解释器” | +| 工具链 | 找到项目的 `.venv`,Poetry、Pipenv、Hatch、virtualenvwrapper 建在项目外的环境,以及电脑上 uv、pyenv、conda、Homebrew、python.org 装的 Python;按 `.python-version` 和 `requires-python` 选版本,见下文“Python 解释器” | | 设置预览 | 语言页和构建工具页画出设置的效果和解释器的查找顺序,见下文“设置预览” | ## 设置 @@ -48,30 +49,22 @@ Pyrefly 和 debugpy 随插件包分发,Python 解释器、pytest、uv、conda Pyrefly 分析代码、运行、测试、调试、读取依赖、安装依赖都用同一个解释器,除非设置了“Python 解释器覆盖路径”:那时构建任务、运行和 pytest 用覆盖路径,Pyrefly 和调试仍用下面找到的解释器。Lithe 按这个顺序找: -1. **项目环境**:为项目固定的解释器;项目里的 `.venv`、`venv`、`.conda`(项目要先被信任);项目的 `.python-version` 和 - `pyproject.toml` 的 `requires-python` 决定选哪个版本。 +1. **项目环境**:为项目固定的解释器;项目里的 `.venv`、`venv`、`.conda`(项目要先被信任);有 `poetry.lock` 或 `Pipfile` 时, + Poetry、Pipenv 为这个项目建的环境;项目的 `.python-version` 和 `pyproject.toml` 的 `requires-python` 决定选哪个版本。 2. **全局默认**:全局固定的解释器,其次默认版本。 -3. **自动发现**:`VIRTUAL_ENV`,`PATH` 里的 `python3`、`python`,然后是 uv、pyenv、conda、python.org 装的 Python。 +3. **自动发现**:`VIRTUAL_ENV`,`PATH` 里的 `python3`、`python`,然后是 uv、pyenv、conda、Homebrew、python.org 装的 Python。 -换解释器在 **设置 → 构建、执行、部署 → 工具链**:为项目或全局固定一个找到的安装,或者添加其他目录。 -「语言与框架 › Python」顶部那一行显示当前用的解释器,点它也会到工具链页。 +`.python-version` 写版本号(如 `3.12`)和 `requires-python` 只选基础解释器,不会选中别的项目的虚拟环境; +`.python-version` 写的是环境名(pyenv-virtualenv 的做法)时,选同名的环境。 -**目前用不了的解释器**([#2316](https://github.com/1lck/Lithe-IDEA/issues/2316)):在 macOS 和 Linux 上,Lithe 拒绝程序链接到安装目录外的 -Python,固定也不行。受影响的有: - -- 建在项目外的虚拟环境:`python -m venv`、`uv venv`、virtualenv 建的,以及 Poetry、Pipenv、virtualenvwrapper 默认建的环境; -- Homebrew 的 Python,它不会出现在安装列表里。 - -在此之前请把环境建在项目里:`python3 -m venv .venv` 或 `uv venv`;Poetry 先运行 `poetry config virtualenvs.in-project true`, -Pipenv 设置 `PIPENV_VENV_IN_PROJECT=1`。也可以固定 uv、pyenv、python.org 装的基础解释器,但那里没有环境里装的包。 - -项目外的环境暂时也可以填进“Python 解释器覆盖路径”,让运行和 pytest 先用上它。 +换解释器:点「语言与框架 › Python」顶部那一行,在下拉菜单里为项目或全局选一个找到的解释器,或者添加其他目录, +例如建在别处的 `python -m venv`、`uv venv` 环境。菜单底部也能打开 **设置 → 构建、执行、部署 → 工具链**。 ## 设置预览 两块预览由插件后端按界面语言、外观和设置窗口宽度画出。它们用示例代码,不读取打开的项目;截图里的路径和版本是测试数据。 -**语言与框架 › Python**:顶部是当前用的 Python 解释器;设置了覆盖路径时,下面多一行说明哪些流程改用它。下面四张卡片各对应一项设置: +**语言与框架 › Python**:顶部是当前用的 Python 解释器,点它打开下拉菜单换解释器;设置了覆盖路径时,下面多一行说明哪些流程改用它。下面四张卡片各对应一项设置: | 卡片 | 画出什么 | | --- | --- | @@ -86,7 +79,7 @@ Pipenv 设置 `PIPENV_VENV_IN_PROJECT=1`。也可以固定 uv、pyenv、python.o 还没应用的修改先显示在预览里,英文浅色外观 -**构建工具 › Python**:先画覆盖路径(有没有设置、设置后谁用它),再画上面三步查找顺序,以及查找到的解释器用在哪些流程。这一页没有设置项,换解释器要到工具链页。 +**构建工具 › Python**:顶部同样是解释器下拉菜单;下面先画覆盖路径(有没有设置、设置后谁用它),再画上面三步查找顺序,以及查找到的解释器用在哪些流程。这一页没有其他设置项。 构建工具 › Python 画出 Lithe 查找 Python 解释器的顺序,深色外观 @@ -113,7 +106,9 @@ Pipenv 设置 `PIPENV_VENV_IN_PROJECT=1`。也可以固定 uv、pyenv、python.o - 后端用 [Rust 插件 SDK](https://github.com/Lithe-IDEA/Lithe-core-rust/tree/main/shared/plugins/sdk/rust) 编写,回答 `pyrefly.resolveLaunch`(启动 Pyrefly 并传入所选解释器)、`settings.view`(两块设置预览)和 `toolchains/query`(读取 conda 登记、uv、pyenv、 - Poetry、Pipenv 环境和项目的版本要求)。后端不保存状态,也不写文件。 + Poetry、Pipenv、Hatch、virtualenvwrapper 环境和项目的版本要求)。后端不保存状态,也不写文件。 +- 虚拟环境的 `bin/python` 通常链接到基础安装。`plugin.json` 的 python 工具定义写了 `executableLinksOutsideHome`, + Lithe 按环境里的路径启动它,Python 因此能找到自己所在的环境和装在里面的包。 - 构建提供者 `scripts/build_provider.py` 由所选解释器以 `python -I -B` 启动,回答 `lithe/build/model`、`test`、`runEntrypoints` 和 `prepareRun`。 它只用 `ast` 和 `tomllib` 读项目,不执行项目代码。 - 测试树由 `test.discoveryCommand` 运行 `scripts/discover_tests.py` 得到;报告和 pytest 缓存在 Lithe 分配的目录里,用完由 Lithe 清理。 @@ -158,16 +153,16 @@ PYTEST_PYTHON=/path/to/python node scripts/test.mjs # 用真实的 Pyre 需要 Node.js 22+、Go、Rust 工具链、`git` 和两个 Python: - `PATH` 里的 `python3` 要是 3.10 或更新(调试用的 debugpy 需要),并且能用 `--copies` 建虚拟环境。Homebrew(`/opt/homebrew/opt/python@3.x/libexec/bin`)或 python.org 装的都可以;uv 装的独立版本复制出来不能运行,Xcode 自带的是 3.9; -- `PYTEST_PYTHON` 指向装了 pytest 的真实安装,不能是虚拟环境(固定解释器的测试会固定它,见 #2316)。例如 - `uv python install 3.12 --install-dir .artifacts/test-python`,再用 `uv pip install --python <它的 python3.12> --break-system-packages pytest`。 +- `PYTEST_PYTHON` 指向装了 pytest 的真实安装,不能是虚拟环境:`RunCurrentFilePinnedInterpreter` 固定它, + `RunCurrentFilePinnedEnvironment` 另用 `python3` 在项目外建虚拟环境来固定。例如 `uv python install 3.12 --install-dir .artifacts/test-python`, + 再用 `uv pip install --python <它的 python3.12> --break-system-packages pytest`。 ```bash node scripts/package.mjs --platform darwin-arm64 -export LITHE_TEST_PYTHON_PLUGIN_ARCHIVE="$PWD/dist/python-support-1.1.0-darwin-arm64.zip" +export LITHE_TEST_PYTHON_PLUGIN_ARCHIVE="$PWD/dist/python-support-1.2.0-darwin-arm64.zip" PYTEST_PYTHON=/path/to/python3.12 node scripts/e2e-host.mjs -# 用同一个包检查 0.8.9:高亮、当前文件运行、固定解释器、手动运行 -PYTEST_PYTHON=/path/to/python3.12 node scripts/e2e-host.mjs --ref desktop-v0.8.9 \ - --run '^TestPythonSupportPlugin(GrammarHighlighting|RunCurrentFile(InterpreterOverride|PinnedInterpreter)?|ManualRunAndDependencies)$' +# 只跑固定解释器的两个用例 +PYTEST_PYTHON=/path/to/python3.12 node scripts/e2e-host.mjs --run '^TestPythonSupportPluginRunCurrentFilePinned' ``` 插件包路径要写绝对路径。脚本把宿主检出到 `.artifacts/lithe-host`,复制 `e2e/host/desktop/` 下的测试后运行;`--source`、`--ref`、`--run` @@ -181,9 +176,9 @@ PYTEST_PYTHON=/path/to/python3.12 node scripts/e2e-host.mjs --ref desktop-v0.8.9 1. 修改 `io.github.lithe-idea.python-support/plugin.json` 的 `version`:修复升修订号,加功能升次版本号,特别大的革新才升主版本号。 依赖还没发布的宿主能力时照样升次版本号,作为预发布版本发布。写好 `docs/releases/v<版本>.md`,合入 `main`。 -2. 推送同名标签,例如 `git tag v1.1.0 && git push origin v1.1.0`。 +2. 推送同名标签,例如 `git tag v1.2.0 && git push origin v1.2.0`。 3. `Release` 工作流核对标签与版本,打六个平台的包并发布 Release,说明里附 SHA-256 和 `docs/releases/v<版本>.md`。 - `release.yml` 的 `PRERELEASE_TAGS` 里的版本标为预发布,目前是 `v0.1.0` 和 `v0.1.1`。 + `release.yml` 的 `PRERELEASE_TAGS` 里的版本标为预发布,目前是 `v0.1.0`、`v0.1.1` 和 `v1.2.0`。 4. Lithe Store 的自动追踪会为稳定版本开合并请求,合并后用户即可更新。 ## 许可 diff --git a/backend/src/discovery.rs b/backend/src/discovery.rs index 52e531a..1f95006 100644 --- a/backend/src/discovery.rs +++ b/backend/src/discovery.rs @@ -28,6 +28,9 @@ struct Installation { home: String, names: BTreeSet, version: Version, + /// A virtual environment belongs to one project. A version request picks + /// it only by its name, never by its version alone. + virtual_environment: bool, } struct Snapshot<'a> { @@ -93,6 +96,17 @@ pub(crate) fn query( if let Some(pipenv) = pipenv_root(user_home.as_deref()) { snapshot.scan(&pipenv, Source::Pipenv)?; } + // virtualenvwrapper keeps environments in ~/.virtualenvs unless WORKON_HOME + // moves them, and so does Hatch when configured to use it. On Windows this + // is already the Pipenv default above. + if !cfg!(windows) && env::var_os("WORKON_HOME").is_none() { + if let Some(home) = &user_home { + snapshot.scan(&home.join(".virtualenvs"), Source::Virtualenvwrapper)?; + } + } + if let Some(hatch) = hatch_root(user_home.as_deref()) { + snapshot.scan_hatch(&hatch)?; + } if let Some((root, directory)) = workspace { project::read(&mut snapshot, &root, &directory)?; } @@ -150,24 +164,49 @@ impl Snapshot<'_> { fn scan(&mut self, root: &Path, source: Source) -> Result<()> { self.watch(root)?; - let Some(root) = canonical_directory(root)? else { - return Ok(()); + for entry in self.entries(root)? { + self.observe(&entry, source)?; + } + Ok(()) + } + + /// Hatch keeps each environment under `//`. The + /// root and each project ID directory are watched, as an environment is + /// added to the latter; a new project name also changes the root. + fn scan_hatch(&mut self, root: &Path) -> Result<()> { + self.watch(root)?; + for project in self.entries(root)? { + for id in self.entries(&project)? { + if canonical_directory(&id)?.is_some() { + self.scan(&id, Source::Hatch)?; + } + } + } + Ok(()) + } + + /// Lists the entries of a directory outside the workspace, skipping hidden + /// ones such as Hatch's `.pythons`. A missing directory has no entries. + fn entries(&mut self, directory: &Path) -> Result> { + let Some(directory) = canonical_directory(directory)? else { + return Ok(Vec::new()); }; if self .workspace .as_ref() - .is_some_and(|workspace| root.starts_with(workspace)) + .is_some_and(|workspace| directory.starts_with(workspace)) { - return Ok(()); + return Ok(Vec::new()); } - for entry in std::fs::read_dir(root).map_err(metadata::io_failure)? { + let mut entries = Vec::new(); + for entry in std::fs::read_dir(directory).map_err(metadata::io_failure)? { self.step()?; let entry = entry.map_err(metadata::io_failure)?; if !entry.file_name().as_encoded_bytes().starts_with(b".") { - self.observe(&entry.path(), source)?; + entries.push(entry.path()); } } - Ok(()) + Ok(entries) } fn observe(&mut self, candidate: &Path, source: Source) -> Result<()> { @@ -190,11 +229,14 @@ impl Snapshot<'_> { existing.names.extend(names); return Ok(()); } - if !metadata::has_safe_executable(&home)? { + if !metadata::has_safe_executable(&home, self.workspace.as_deref())? { return Ok(()); } - let Some(Metadata { version, input }) = - metadata::version(&home, candidate, source, || self.step())? + let Some(Metadata { + version, + input, + virtual_environment, + }) = metadata::version(&home, candidate, source, || self.step())? else { return Ok(()); }; @@ -210,6 +252,7 @@ impl Snapshot<'_> { home: wire_home, names, version, + virtual_environment, }, ); if self.installations.len() > MAX_INSTALLATIONS { @@ -277,6 +320,21 @@ fn poetry_root(home: Option<&Path>) -> Option { }) } +fn hatch_root(home: Option<&Path>) -> Option { + let data = absolute_env("HATCH_DATA_DIR").or_else(|| { + if cfg!(target_os = "macos") { + home.map(|path| path.join("Library/Application Support/hatch")) + } else if cfg!(windows) { + absolute_env("LOCALAPPDATA").map(|path| path.join("hatch")) + } else { + absolute_env("XDG_DATA_HOME") + .or_else(|| home.map(|path| path.join(".local/share"))) + .map(|path| path.join("hatch")) + } + }); + data.map(|path| path.join("env/virtual")) +} + fn pipenv_root(home: Option<&Path>) -> Option { absolute_env("WORKON_HOME").or_else(|| { home.map(|path| { diff --git a/backend/src/discovery/metadata.rs b/backend/src/discovery/metadata.rs index 14ea3e8..d7a4df4 100644 --- a/backend/src/discovery/metadata.rs +++ b/backend/src/discovery/metadata.rs @@ -17,11 +17,16 @@ pub(super) enum Source { Pyenv, Poetry, Pipenv, + Hatch, + Virtualenvwrapper, } pub(super) struct Metadata { pub(super) version: Version, pub(super) input: Option, + /// The version came from `pyvenv.cfg`: the home is a virtual environment + /// made from some base interpreter, not an installation of its own. + pub(super) virtual_environment: bool, } pub(super) fn io_failure(_: io::Error) -> Failure { @@ -78,25 +83,49 @@ pub(super) fn read_text(path: &Path, within: Option<&Path>) -> Result Result { - let layouts = if cfg!(windows) { - ["Scripts/python.exe", "python.exe"] +/// Mirrors the host check of an installation's program so the provider only +/// reports homes the host accepts. Core decides on the first layout that exists. +/// A program inside the home is accepted as is. A virtual environment's program +/// usually links to its base interpreter outside the environment; the tool +/// definition allows that (`executableLinksOutsideHome`) as long as every +/// directory on the layout path, such as `bin`, stays inside the home. Nothing +/// on the way may enter the workspace. +pub(super) fn has_safe_executable(home: &Path, workspace: Option<&Path>) -> Result { + let layouts: [&[&str]; 2] = if cfg!(windows) { + [&["Scripts", "python.exe"], &["python.exe"]] } else { - ["bin/python3", "bin/python"] + [&["bin", "python3"], &["bin", "python"]] }; - for layout in layouts { - let path = home.join(layout); - let Some(canonical) = optional(dunce::canonicalize(&path))? else { + let in_workspace = |path: &Path| workspace.is_some_and(|root| path.starts_with(root)); + for segments in layouts { + let path = segments + .iter() + .fold(home.to_path_buf(), |path, segment| path.join(segment)); + if optional(fs::symlink_metadata(&path))?.is_none() { continue; + } + // Skipping a present but unusable layout and looking for the next one + // would report a home the host rejects. + let Some(target) = optional(dunce::canonicalize(&path))? else { + return Ok(false); }; - // Core checks the first present layout and rejects an escaping target. - // Skipping that target and looking for a second layout would emit a - // candidate the host cannot validate. - if !canonical.starts_with(home) { + if in_workspace(&target) { return Ok(false); } - let Some(metadata) = optional(fs::metadata(canonical))? else { - continue; + if !target.starts_with(home) { + let mut parent = home.to_path_buf(); + for segment in &segments[..segments.len() - 1] { + parent.push(segment); + let Some(directory) = canonical_directory(&parent)? else { + return Ok(false); + }; + if !directory.starts_with(home) || in_workspace(&directory) { + return Ok(false); + } + } + } + let Some(metadata) = optional(fs::metadata(&target))? else { + return Ok(false); }; #[cfg(unix)] let executable = { @@ -127,6 +156,7 @@ pub(super) fn version( return Ok(Some(Metadata { version, input: Some(venv_cfg), + virtual_environment: true, })); } } @@ -147,6 +177,7 @@ pub(super) fn version( Ok(version.map(|version| Metadata { version, input: None, + virtual_environment: false, })) } @@ -194,6 +225,7 @@ fn conda_version(home: &Path, mut step: impl FnMut() -> Result<()>) -> Result Option { .ok() .filter(|_: &Version| numeric_release(value).is_some()) } + +#[cfg(all(test, unix))] +mod tests { + use super::has_safe_executable; + use std::fs; + use std::os::unix::fs::{symlink, PermissionsExt}; + use std::path::{Path, PathBuf}; + + /// A scratch directory removed when the test ends, canonical like the homes + /// discovery passes in. + struct Scratch(PathBuf); + + impl Scratch { + fn new(name: &str) -> Self { + let path = std::env::temp_dir().join(format!( + "python-support-metadata-{name}-{}", + std::process::id() + )); + let _ = fs::remove_dir_all(&path); + fs::create_dir_all(&path).unwrap(); + Self(dunce::canonicalize(path).unwrap()) + } + } + + impl Drop for Scratch { + fn drop(&mut self) { + let _ = fs::remove_dir_all(&self.0); + } + } + + fn interpreter(path: &Path) { + fs::create_dir_all(path.parent().unwrap()).unwrap(); + fs::write(path, "#!/bin/sh\n").unwrap(); + fs::set_permissions(path, fs::Permissions::from_mode(0o755)).unwrap(); + } + + /// A venv made by `python -m venv` outside the project: `bin/python3` + /// links to the base interpreter in another directory. + fn environment(scratch: &Path, target: &Path) -> PathBuf { + let home = scratch.join("env"); + fs::create_dir_all(home.join("bin")).unwrap(); + symlink(target, home.join("bin/python3")).unwrap(); + home + } + + #[test] + fn an_environment_linking_to_its_base_interpreter_is_reported() { + let scratch = Scratch::new("linked"); + let base = scratch.0.join("base/bin/python3.12"); + interpreter(&base); + let home = environment(&scratch.0, &base); + assert!(has_safe_executable(&home, Some(&scratch.0.join("project"))).unwrap()); + } + + #[test] + fn a_program_inside_the_home_is_reported() { + let scratch = Scratch::new("inside"); + let home = scratch.0.join("install"); + interpreter(&home.join("bin/python3")); + assert!(has_safe_executable(&home, None).unwrap()); + } + + #[test] + fn a_program_in_the_workspace_is_not_reported() { + let scratch = Scratch::new("workspace"); + let workspace = scratch.0.join("project"); + let target = workspace.join("tools/python3"); + interpreter(&target); + let home = environment(&scratch.0, &target); + assert!(!has_safe_executable(&home, Some(&workspace)).unwrap()); + } + + #[test] + fn a_bin_directory_leaving_the_home_is_not_reported() { + let scratch = Scratch::new("bin"); + let base = scratch.0.join("base"); + interpreter(&base.join("bin/python3")); + let home = scratch.0.join("env"); + fs::create_dir_all(&home).unwrap(); + symlink(base.join("bin"), home.join("bin")).unwrap(); + assert!(!has_safe_executable(&home, None).unwrap()); + } + + #[test] + fn a_broken_first_layout_decides_like_the_host() { + let scratch = Scratch::new("dangling"); + let home = environment(&scratch.0, &scratch.0.join("missing/python3")); + interpreter(&home.join("bin/python")); + assert!(!has_safe_executable(&home, None).unwrap()); + } +} diff --git a/backend/src/discovery/project.rs b/backend/src/discovery/project.rs index 3faf324..88cc773 100644 --- a/backend/src/discovery/project.rs +++ b/backend/src/discovery/project.rs @@ -98,13 +98,20 @@ fn project_file( // alternatives. A manager pin and the project's compatibility range apply // together, so publish one request anchored at the file selecting the version. if let Some((source, request)) = selected_version { + // A virtual environment answers only to its own name, as a + // pyenv-virtualenv pin names it; by version, the pin means a base + // interpreter, not some other project's environment made from one. let installation = choose(snapshot, |candidate| { allows_version(&candidate.version) && candidate .names .iter() .filter_map(|name| name.to_str()) - .any(|name| matches_version_file(&request, name, &candidate.version)) + .any(|name| { + name == request + || (!candidate.virtual_environment + && matches_version_file(&request, name, &candidate.version)) + }) }); statement( snapshot, @@ -115,7 +122,9 @@ fn project_file( "compatible", )?; } else if let Some((source, request, _)) = &project_requirement { - let installation = choose(snapshot, |candidate| allows_version(&candidate.version)); + let installation = choose(snapshot, |candidate| { + !candidate.virtual_environment && allows_version(&candidate.version) + }); statement( snapshot, source, diff --git a/backend/src/view/language.rs b/backend/src/view/language.rs index c343e64..9ecb2a8 100644 --- a/backend/src/view/language.rs +++ b/backend/src/view/language.rs @@ -145,7 +145,7 @@ struct Card<'a> { pub fn view(settings: &Settings, words: &Words, width: Option) -> Vec { let mut tools: Vec = TOOLS .iter() - .map(|tool| json!({ "type": "tool", "tool": tool })) + .map(|tool| json!({ "type": "tool", "tool": tool, "choose": true })) .collect(); if let Some(path) = &settings.interpreter_override { tools.push(json!({ diff --git a/backend/src/view/mod.rs b/backend/src/view/mod.rs index 9e02fdd..8839787 100644 --- a/backend/src/view/mod.rs +++ b/backend/src/view/mod.rs @@ -73,7 +73,7 @@ fn render(event: &ViewEvent) -> Result<(Vec, u64), PluginError> { PYTHON_REGION => { let settings = Settings::read(event); let nodes = vec![ - json!({ "type": "tool", "tool": PYTHON_TOOL }), + json!({ "type": "tool", "tool": PYTHON_TOOL, "choose": true }), resolution::canvas(words, settings.interpreter_override.as_deref(), event.width), ]; Ok((nodes, settings.unrecognized)) @@ -517,6 +517,7 @@ mod tests { .iter() .map(|row| { assert_eq!(row["type"], "tool"); + assert_eq!(row["choose"], true, "the row is the interpreter picker"); row["tool"].as_str().unwrap() }) .collect(); @@ -525,7 +526,10 @@ mod tests { let python = nodes(PYTHON_REGION, "en", json!({}), json!({})); assert_eq!(python.len(), 2); - assert_eq!(python[0], json!({ "type": "tool", "tool": "python" })); + assert_eq!( + python[0], + json!({ "type": "tool", "tool": "python", "choose": true }) + ); assert_eq!(canvas(&python)["id"], resolution::CANVAS_ID); } diff --git a/backend/src/view/words.rs b/backend/src/view/words.rs index c1c273f..33b9eff 100644 --- a/backend/src/view/words.rs +++ b/backend/src/view/words.rs @@ -115,7 +115,7 @@ const ZH: Words = Words { off: "关", interpreter_title: "Python 解释器", - interpreter_info: "Pyrefly 分析代码和调试用这个解释器,Pyrefly 从它的 site-packages 解析第三方库;没有设置「Python 解释器覆盖路径」时,构建、运行、pytest 和安装依赖也用它。点击这一行,到「工具链」页为项目或全局选择 .venv、uv、conda、pyenv 等环境,或添加其他目录。", + interpreter_info: "Pyrefly 分析代码和调试用这个解释器,Pyrefly 从它的 site-packages 解析第三方库;没有设置「Python 解释器覆盖路径」时,构建、运行、pytest 和安装依赖也用它。点击这一行,在下拉菜单里为项目或全局选择 .venv、uv、conda、pyenv、Poetry、Pipenv、Hatch 等环境,或添加其他目录;菜单底部也能打开「工具链」页。", override_banner: override_banner_zh, mode_title: "类型检查模式", @@ -207,7 +207,7 @@ const EN: Words = Words { off: "Off", interpreter_title: "Python interpreter", - interpreter_info: "Pyrefly analyzes the code and Lithe debugs with this interpreter; Pyrefly resolves third-party imports from its site-packages. Unless Python executable override is set, Lithe also builds, runs, tests and installs packages with it. Choose the row to pick a .venv, uv, conda or pyenv environment, or another directory, for the project or for all projects on the Toolchains page.", + interpreter_info: "Pyrefly analyzes the code and Lithe debugs with this interpreter; Pyrefly resolves third-party imports from its site-packages. Unless Python executable override is set, Lithe also builds, runs, tests and installs packages with it. Choose the row to pick a .venv, uv, conda, pyenv, Poetry, Pipenv or Hatch environment, or another directory, for the project or for all projects; the menu also opens the Toolchains page.", override_banner: override_banner_en, mode_title: "Type checking mode", diff --git a/docs/assets/settings-previews/build-tools-zh-Hans-dark.png b/docs/assets/settings-previews/build-tools-zh-Hans-dark.png index cd84b2b..c11fdbc 100644 Binary files a/docs/assets/settings-previews/build-tools-zh-Hans-dark.png and b/docs/assets/settings-previews/build-tools-zh-Hans-dark.png differ diff --git a/docs/assets/settings-previews/language-en-draft-light.png b/docs/assets/settings-previews/language-en-draft-light.png index 7a97759..0a0618f 100644 Binary files a/docs/assets/settings-previews/language-en-draft-light.png and b/docs/assets/settings-previews/language-en-draft-light.png differ diff --git a/docs/assets/settings-previews/language-zh-Hans-dark.png b/docs/assets/settings-previews/language-zh-Hans-dark.png index 30249e7..443d173 100644 Binary files a/docs/assets/settings-previews/language-zh-Hans-dark.png and b/docs/assets/settings-previews/language-zh-Hans-dark.png differ diff --git a/docs/feature-matrix.md b/docs/feature-matrix.md index 07e9c60..667ddc0 100644 --- a/docs/feature-matrix.md +++ b/docs/feature-matrix.md @@ -12,15 +12,15 @@ | 能力域 | 功能项 | `darwin-arm64` | `darwin-x64` | `windows-x64` / `windows-arm64` | `linux-x64` / `linux-arm64` | 最近实机验证 | 实现与测试证据路径(本仓库) | | --- | --- | --- | --- | --- | --- | --- | --- | -| Python 设置效果预览 (`settingRegions`) | 「语言与框架 → Python」顶部显示当前解释器(工具行,点击到「工具链」页),设置了覆盖路径时下面多一行说明;四张卡片画出类型检查模式(按「显示类型错误」的四档画实际效果)、诊断范围、自动导入补全和补全函数括号的效果,随设置草稿更新。「构建工具 → Python」先画覆盖路径,再画解释器的三步查找顺序和用途。预览使用固定示例,保存仍由宿主表单处理。 | ✅ 包内后端与无头设置窗口通过 | ⏳ 待归档与宿主验证 | ⏳ 待归档与宿主验证 | ⏳ 待归档与宿主验证 | `2026-11-23`(`darwin-arm64`,固定宿主 `60885168`,中文深色与英文浅色、草稿、窗口变宽) | `backend/src/view/`
`scripts/test.mjs`
`e2e/host/desktop/internal/settingswindow/python_settings_preview_e2e_test.go` | -| Python 解释器覆盖设置 | 「设置 → 语言与框架 → Python」的 `pythonExecutable` 覆盖路径:构建任务、当前文件运行、手动运行和 pytest 用它,不按工具链查找;Pyrefly 和调试仍用工具链解析出的解释器。已保存的值继续读取。 | ✅ 已验证(macOS ARM64,当前文件运行端到端) | ⏳ 平台清单已验证 | ⏳ 平台清单已验证 | ⏳ 平台清单已验证 | `2026-11-23`(`darwin-arm64`,Lithe 0.8.9 与固定宿主 `60885168`) | `io.github.lithe-idea.python-support/plugin.json`
`io.github.lithe-idea.python-support/scripts/run_entrypoint.py`
`scripts/package/archives.test.mjs`
`e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go` | +| Python 设置效果预览 (`settingRegions`) | 「语言与框架 → Python」顶部显示当前解释器(工具行,点击打开下拉菜单,在原处为项目或全局选择解释器或添加目录,菜单底部可到「工具链」页),设置了覆盖路径时下面多一行说明;四张卡片画出类型检查模式(按「显示类型错误」的四档画实际效果)、诊断范围、自动导入补全和补全函数括号的效果,随设置草稿更新。「构建工具 → Python」顶部同样是解释器下拉菜单,下面先画覆盖路径,再画解释器的三步查找顺序和用途。预览使用固定示例,保存仍由宿主表单处理。 | ✅ 包内后端与无头设置窗口通过 | ⏳ 待归档与宿主验证 | ⏳ 待归档与宿主验证 | ⏳ 待归档与宿主验证 | `2026-11-23`(`darwin-arm64`,宿主 `58b527ed`(含 [#2321](https://github.com/1lck/Lithe-IDEA/pull/2321)),中文深色与英文浅色、草稿、窗口变宽) | `backend/src/view/`
`scripts/test.mjs`
`e2e/host/desktop/internal/settingswindow/python_settings_preview_e2e_test.go` | +| Python 解释器覆盖设置 | 「设置 → 语言与框架 → Python」的 `pythonExecutable` 覆盖路径:构建任务、当前文件运行、手动运行和 pytest 用它,不按工具链查找;Pyrefly 和调试仍用工具链解析出的解释器。已保存的值继续读取。 | ✅ 已验证(macOS ARM64,当前文件运行端到端) | ⏳ 平台清单已验证 | ⏳ 平台清单已验证 | ⏳ 平台清单已验证 | `2026-11-23`(`darwin-arm64`,宿主 `58b527ed`(含 [#2321](https://github.com/1lck/Lithe-IDEA/pull/2321))) | `io.github.lithe-idea.python-support/plugin.json`
`io.github.lithe-idea.python-support/scripts/run_entrypoint.py`
`scripts/package/archives.test.mjs`
`e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go` | | 语言基础 (`languages`) | `.py` / `.pyi` / `.pyw` 识别、`#` 行注释、括号/引号配对、项目标记与 `.venv` / `venv` / `.conda` 依赖目录 | ✅ 已验证 | ⏳ pending(归档与清单已校验) | ⏳ pending(归档与 Windows 清单已校验) | ⏳ pending(归档与清单已校验) | `2026-11-20`(`darwin-arm64`,0.8.9 复验 `.py` 高亮) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go`
`e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go` | | 无后缀 Python 脚本 | 支持 TextMate 首行匹配的桌面按解释器路径或 `env` shebang 打开,提供 Python 高亮、注释与 Pyrefly 诊断 | ✅ 已验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | `2026-11-20`(`darwin-arm64`,桌面 `645a3aee8`) | `io.github.lithe-idea.python-support/grammars/python.first-line.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go` | | 插件后端与语言服务器启动解析 (`backend` + `languageServers`) | 包内 Rust SDK 后端协商 `litheLogging` 0 与 `litheFunctions` 0。解析 `pyrefly lsp` 启动,传入宿主提供的解释器,缺失时使用 Pyrefly 原生检测。 | ✅ 已验证(桌面主线) | ⏳ 归档已校验 | ⏳ 待 CI 与宿主验收 | ⏳ 待 CI 与宿主验收 | 2026-11-20(macOS ARM64,桌面主线) | `backend/src/pyrefly.rs`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go`
`e2e/host/desktop/internal/workbench/python_editor_debug_e2e_test.go` | -| 工具链与环境自动发现 (`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/*`)。Homebrew 规则保留,但它的 `libexec/bin/python3` 链接到安装目录外,Core 目前以 `unsafePath` 跳过([#2316](https://github.com/1lck/Lithe-IDEA/issues/2316))。 | ✅ 已验证 | ⏳ pending(清单与 Core 规则已校验) | ⏳ pending(`Scripts/python.exe` / `python.exe` 布局与环境变量发现规则已通过 Core 校验) | ⏳ pending(清单与 Core 规则已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | +| 工具链与环境自动发现 (`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/*`)。工具定义声明 `executableLinksOutsideHome`:项目外虚拟环境和 Homebrew 的 `bin/python3` 链接到主目录外时,Core 按主目录下的布局路径探测和启动,Python 仍在自己的环境里运行([#2316](https://github.com/1lck/Lithe-IDEA/issues/2316),需要 Core #177 与宿主 #2321;旧宿主不认识这个字段,会拒绝整个清单)。 | ✅ 已验证(固定项目外的 venv 端到端) | ⏳ pending(清单与 Core 规则已校验) | ⏳ pending(`Scripts/python.exe` / `python.exe` 布局与环境变量发现规则已通过 Core 校验) | ⏳ pending(清单与 Core 规则已校验) | `2026-11-23`(`darwin-arm64`,宿主 `58b527ed`(含 [#2321](https://github.com/1lck/Lithe-IDEA/pull/2321));Homebrew 未实机验证) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go`
`e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go` | | 构建模型与运行 (`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`
`io.github.lithe-idea.python-support/scripts/build_provider.py`
`io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | -| 当前文件运行 (`buildProviders: 1`) | 工具栏支持带 `__main__` 入口的脚本或包内 `__main__.py`。使用工具链解析出的解释器(包括在「工具链」页为项目固定的解释器),设置了覆盖路径时用覆盖路径。包入口执行前核对文件来源。 | ✅ 已验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | 2026-11-23(macOS ARM64,Lithe 0.8.9 与固定宿主 `60885168` 工作台端到端,含固定解释器与覆盖路径) | `io.github.lithe-idea.python-support/scripts/build_provider.py`
`io.github.lithe-idea.python-support/scripts/run_entrypoint.py`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go` | -| 手动 Python 运行配置 (`runConfigurationTypes: 0`) | 「运行/调试配置 → + → Python」支持脚本路径和模块名、解释器选项、参数、环境变量和工作目录。使用工具链为项目解析出的解释器,设置了覆盖路径时用覆盖路径。 | ✅ 已验证(macOS ARM64) | ⏳ 待实机验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | 2026-11-23(Lithe 0.8.9 与固定宿主 `60885168`,脚本与模块) | `io.github.lithe-idea.python-support/plugin.json`
`e2e/host/desktop/internal/workbench/python_project_workflow_e2e_test.go` | +| 当前文件运行 (`buildProviders: 1`) | 工具栏支持带 `__main__` 入口的脚本或包内 `__main__.py`。使用工具链解析出的解释器(包括为项目固定的安装或项目外的虚拟环境),设置了覆盖路径时用覆盖路径。包入口执行前核对文件来源。 | ✅ 已验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | 2026-11-23(macOS ARM64,宿主 `58b527ed`(含 [#2321](https://github.com/1lck/Lithe-IDEA/pull/2321))工作台端到端,含固定安装、固定项目外 venv 与覆盖路径) | `io.github.lithe-idea.python-support/scripts/build_provider.py`
`io.github.lithe-idea.python-support/scripts/run_entrypoint.py`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go` | +| 手动 Python 运行配置 (`runConfigurationTypes: 0`) | 「运行/调试配置 → + → Python」支持脚本路径和模块名、解释器选项、参数、环境变量和工作目录。使用工具链为项目解析出的解释器,设置了覆盖路径时用覆盖路径。 | ✅ 已验证(macOS ARM64) | ⏳ 待实机验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | 2026-11-23(宿主 `58b527ed`(含 [#2321](https://github.com/1lck/Lithe-IDEA/pull/2321)),脚本与模块) | `io.github.lithe-idea.python-support/plugin.json`
`e2e/host/desktop/internal/workbench/python_project_workflow_e2e_test.go` | | 构建面板依赖树 (`litheDependencies`) | 展开「依赖」时用 `python -I -B` 读取所选 Python 环境中已安装的包、版本和依赖关系,跳过用户级 site-packages 及其启动钩子,解析 PEP 508 条件和可选依赖。仅有 Conda 环境清单的项目也可加载。支持无 pip 的环境。 | ✅ 已验证(macOS ARM64) | ⏳ 待实机验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | 2026-11-21(固定宿主与打包命令) | `io.github.lithe-idea.python-support/scripts/dependencies.py`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_project_workflow_e2e_test.go` | | 动态 `pytest` 测试树与测试执行 (`litheTestDiscovery` + `junitXml`) | `test.discoveryCommand` 通过 `python -I -B` 启动包内 `discover_tests.py`。`pytest --collect-only` 收集函数、类方法、参数化用例与 doctest,并将 `litheTestDiscovery` v0 写入宿主提供的 `${outputFile}`。无测试时返回空列表,收集失败或选择器超出契约时整次失败。报告与缓存由宿主清理。`lithe/build/test` 以精确 node ID 或 JUnit 类名重跑,继续提供流式进度和 JUnit 报告。 | ✅ 已验证(桌面主线) | ⏳ 待实机验证 | ⏳ 待 CI 与宿主验收 | ⏳ 待 CI 与宿主验收 | 2026-11-20(macOS ARM64,桌面主线) | `io.github.lithe-idea.python-support/scripts/discover_tests.py`
`io.github.lithe-idea.python-support/scripts/build_provider.py`
`io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | | 独立工具构建系统 (`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`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | @@ -28,13 +28,13 @@ | 终端输出跳转 (`outputLinkMatchers`) | Python Traceback `File "...", line N` 点击定位源码与行号 | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | | 新建项目向导 (`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`
`io.github.lithe-idea.python-support/templates/python/`
`scripts/package/archives.test.mjs`
`e2e/host/desktop/internal/projectgen/python_integration_test.go` | | 国际化 (`l10n`) | 英文默认文案 + `l10n/zh-Hans.json` 简体中文完整设置与分组翻译。设置预览的文字由包内后端按宿主语言选择中文或英文。 | ✅ 已验证 | ⏳ pending(归档与 Core `settingsState` 已校验) | ⏳ pending(归档与 Core `settingsState` 已校验) | ⏳ pending(归档与 Core `settingsState` 已校验) | `2026-11-23`(`darwin-arm64`,设置预览中英文) | `io.github.lithe-idea.python-support/l10n/zh-Hans.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | -| 工具链提供者 (`litheToolchains` / `toolchains/query`) | 包内 Rust 后端在全局与项目上下文读取 Conda 登记、uv、pyenv、Poetry/Pipenv 环境以及项目版本声明。Pipenv 默认环境按完整的 `Pipfile` 路径识别,所选解释器须满足同目录的项目版本约束。安装、要求与观察路径作为事实交回宿主验证。 | ✅ 已验证(桌面主线) | ⏳ 归档已校验 | ⏳ 待宿主验收 | ⏳ 待宿主验收 | 2026-11-20(macOS ARM64,桌面主线) | `backend/src/discovery.rs`
`backend/src/discovery/project.rs`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | +| 工具链提供者 (`litheToolchains` / `toolchains/query`) | 包内 Rust 后端在全局与项目上下文读取 Conda 登记、uv、pyenv、Poetry/Pipenv、Hatch(`HATCH_DATA_DIR` 或平台数据目录下的 `env/virtual`,跳过隐藏的 `.pythons`)、virtualenvwrapper(`WORKON_HOME`,未设置时非 Windows 上的 `~/.virtualenvs`)环境以及项目版本声明。Pipenv 默认环境按完整的 `Pipfile` 路径识别,所选解释器须满足同目录的项目版本约束。`.python-version` 的版本号和 `requires-python` 只选基础解释器;有 `pyvenv.cfg` 的虚拟环境只按名字匹配,不会选到别的项目的环境。安装、要求与观察路径作为事实交回宿主验证。 | ✅ 已验证 | ⏳ 归档已校验 | ⏳ 待宿主验收 | ⏳ 待宿主验收 | 2026-11-23(macOS ARM64,`scripts/test.mjs` 与宿主 `58b527ed`(含 [#2321](https://github.com/1lck/Lithe-IDEA/pull/2321))) | `backend/src/discovery.rs`
`backend/src/discovery/project.rs`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | ## 宿主版本与验证 -- 插件要求宿主声明 `toolchainProviders: 0`、`buildSystems: 1`、`buildProviders: 1`、`runConfigurationTypes: 0` 和 `languages: 0`。桌面 0.8.9 支持安装、当前文件运行和原有 Python 功能。支持 TextMate 首行匹配的桌面会额外识别无后缀脚本。 -- `e2e/host/lithe-host.json` 固定桌面主线提交 `60885168`。 -- 插件 CI 用同一个 macOS ARM64 ZIP 在 0.8.9 验证普通 Python 高亮、当前文件运行(含为项目固定的解释器和覆盖路径)、手动运行配置和依赖树,并在固定的桌面主线上运行完整宿主套件,额外覆盖设置预览、项目生成、解释器切换、pytest、debugpy 和无后缀脚本的编辑诊断。 +- 插件要求宿主声明 `toolchainProviders: 0`、`buildSystems: 1`、`buildProviders: 1`、`runConfigurationTypes: 0` 和 `languages: 0`。1.2.0 还用到两项能力版本 0 内的补充:工具定义的 `executableLinksOutsideHome`(Core #177、宿主 #2321)和设置区域工具行的 `choose`(宿主 #2312)。0.8.14 及更早的桌面不认识前者,会拒绝整个清单,所以 1.2.0 需要之后发布的桌面;1.1.0 仍支持 0.8.9 起的桌面。 +- `e2e/host/lithe-host.json` 固定宿主主线提交 `58b527ed`(#2321 的合入提交,Core 固定在 #177 的分支提交 `33e6b60`,源码与 Core 主线 `4880022` 相同)。 +- 插件 CI 用 macOS ARM64 ZIP 在固定宿主上运行完整宿主套件:设置预览、项目生成、当前文件运行(项目 `.venv`、固定安装、固定项目外 venv、覆盖路径)、手动运行配置、依赖树、解释器切换、pytest、debugpy 和无后缀脚本的编辑诊断。旧宿主不能安装 1.2.0,所以去掉了 0.8.9 的兼容子集;新桌面发布后,固定宿主就是最低支持版本。 - macOS ARM64 的工作台测试从 ZIP 安装插件,改变项目版本要求以切换外部解释器,检查全局候选和项目 `.venv` 信任,精确重跑一个参数化 pytest 用例并核对 JUnit。 - 无头工作台打开 `.py` 后,Pyrefly 返回所选环境独有模块的类型诊断。debugpy 使用同一环境执行当前文件,并将日志写入宿主分配目录。关闭后,已安装插件的文件清单和 SHA-256 与启动前一致。 -- 宿主按 Core 的文件事实校验安装。程序链接到安装目录外的安装会以 `unsafePath` 被拒绝,包括在 macOS 和 Linux 上建在项目外的虚拟环境(venv、`uv venv`、virtualenv、Poetry、Pipenv)和 Homebrew 的 Python,固定、`VIRTUAL_ENV` 和发现规则都一样([#2316](https://github.com/1lck/Lithe-IDEA/issues/2316))。项目内环境由宿主信任流程单独处理。所以固定解释器的端到端用例固定的是 `PYTEST_PYTHON` 指向的真实安装。 +- 宿主按 Core 的文件事实校验安装。python 工具定义声明了 `executableLinksOutsideHome`,程序链接到主目录外时,宿主观测布局路径上的各级目录,Core 确认它们都在主目录内、不在工作区里,再按布局路径启动([#2316](https://github.com/1lck/Lithe-IDEA/issues/2316))。`RunCurrentFilePinnedEnvironment` 在项目外建一个符号链接式的 venv 并固定它,运行输出的 `sys.prefix` 必须是这个环境;去掉这个字段后同一用例失败。项目内环境由宿主信任流程单独处理。 diff --git a/docs/releases/v1.2.0.md b/docs/releases/v1.2.0.md new file mode 100644 index 0000000..b595047 --- /dev/null +++ b/docs/releases/v1.2.0.md @@ -0,0 +1,33 @@ +## 中文 + +- 「设置 › 语言与框架 › Python」和「设置 › 构建、执行、部署 › 构建工具 › Python」顶部的解释器那一行变成了下拉菜单:点它可以在原处为项目或全局选择一个找到的解释器,或者添加其他目录;菜单底部仍能打开「工具链」页。以前点击只会跳到「工具链」页。 +- 建在项目外的虚拟环境可以用作解释器了([#2316](https://github.com/1lck/Lithe-IDEA/issues/2316))。在 macOS 和 Linux 上,这类环境里的 `python` 通常链接到创建它的基础 Python,以前 Lithe 会拒绝它们,现在按环境里的路径启动,Pyrefly、运行、pytest、调试和依赖树都能看到装在环境里的包: + - `python -m venv`、`uv venv`、virtualenv 建在别处的环境,可以在下拉菜单里添加它的目录; + - 项目有 `poetry.lock` 或 `Pipfile` 时,Poetry、Pipenv 为这个项目建的环境会自动选中; + - Homebrew 安装的 Python 也会出现在找到的解释器里。 +- 新找到两类环境:Hatch 的虚拟环境(`HATCH_DATA_DIR`,没有设置时是平台的数据目录),以及 virtualenvwrapper 的环境(`WORKON_HOME`,没有设置时 macOS 和 Linux 上的 `~/.virtualenvs`)。 +- `.python-version` 写版本号(例如 `3.12`)或 `pyproject.toml` 写了 `requires-python` 时,Lithe 只选基础解释器,不会选到别的项目的虚拟环境。`.python-version` 写的是环境名时(pyenv-virtualenv 的做法),仍选同名的环境。 + +### 升级与兼容性 + +这是预发布版本,需要 0.8.14 之后发布的 Lithe 桌面端。旧版本的 Lithe 读不了这个版本的插件清单,不能安装它;请继续使用 Python Support v1.1.0,它支持 Lithe 0.8.9 或更新版本。已经保存的设置和固定的解释器都继续生效。 + +调试仍需要 Python 3.10 或更新版本。 + +--- + +## English + +- The interpreter row at the top of **Settings › Languages & Frameworks › Python** and **Settings › Build, Execution, Deployment › Build Tools › Python** is now a drop-down menu. Click it to choose a found interpreter for the project or for all projects, or to add another directory, right where you are. The menu still opens the Toolchains page at the bottom. Clicking the row used to only open the Toolchains page. +- Virtual environments outside the project can now be used as the interpreter ([#2316](https://github.com/1lck/Lithe-IDEA/issues/2316)). On macOS and Linux the `python` in such an environment usually links to the base Python it was made from, and Lithe used to refuse it. Lithe now starts it from the environment's own path, so Pyrefly, runs, pytest, debugging and the dependency tree all see the packages installed in the environment: + - For an environment made elsewhere by `python -m venv`, `uv venv` or virtualenv, add its directory from the drop-down menu. + - When the project has a `poetry.lock` or a `Pipfile`, the environment Poetry or Pipenv made for the project is chosen automatically. + - Python installed by Homebrew is also among the found interpreters. +- Two more kinds of environments are found: Hatch virtual environments (in `HATCH_DATA_DIR`, or the platform's data directory when it is not set), and virtualenvwrapper environments (in `WORKON_HOME`, or `~/.virtualenvs` on macOS and Linux when it is not set). +- When `.python-version` names a version (such as `3.12`) or `pyproject.toml` sets `requires-python`, Lithe chooses only base interpreters, never another project's virtual environment. When `.python-version` names an environment, as pyenv-virtualenv does, Lithe still chooses the environment with that name. + +### Upgrade and compatibility + +This is a prerelease. It requires a Lithe desktop release after 0.8.14. Earlier versions of Lithe cannot read this version's plugin manifest and cannot install it; keep using Python Support v1.1.0, which supports Lithe 0.8.9 or later. Settings you have saved and interpreters you have pinned keep working. + +Debugging still requires Python 3.10 or later. diff --git a/e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go b/e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go index 1276edf..e305ed3 100644 --- a/e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go +++ b/e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go @@ -27,6 +27,10 @@ const ( projectEnvironment pythonRunInterpreter = iota // An installation pinned for the project, as the Toolchains page does. pinnedInstallation + // A virtual environment outside the project, pinned for the project. Its + // python links to the interpreter it was made from, outside the + // environment, so Lithe must start it from the environment's own path. + pinnedEnvironment // The Python executable override setting, which build, run and pytest // use before the lookup. executableOverride @@ -43,6 +47,13 @@ func TestPythonSupportPluginRunCurrentFilePinnedInterpreter(t *testing.T) { checkPythonCurrentFileRun(t, pinnedInstallation) } +// TestPythonSupportPluginRunCurrentFilePinnedEnvironment pins a virtual +// environment made outside the project and expects the run to happen inside +// it: sys.prefix is the environment, not the interpreter it links to. +func TestPythonSupportPluginRunCurrentFilePinnedEnvironment(t *testing.T) { + checkPythonCurrentFileRun(t, pinnedEnvironment) +} + // TestPythonSupportPluginRunCurrentFileInterpreterOverride sets the Python // executable override to an environment outside the project and expects the // run to use it over the project's .venv. @@ -120,11 +131,17 @@ func checkPythonCurrentFileRun(t *testing.T, interpreter pythonRunInterpreter) { }) installPythonArchive(t, ctx, h.app.plugins, archive) h.app.reloadPluginLanguages() - if interpreter == pinnedInstallation { + switch interpreter { + case pinnedInstallation: home, version := pythonInstallationForE2E(t, ctx, cmp.Or(os.Getenv("PYTEST_PYTHON"), python)) wantPrefix = home addPythonInstallationForE2E(t, ctx, h, home) pinPythonForE2E(t, ctx, kernel, root, home, version) + case pinnedEnvironment: + home, version := externalPythonEnvironmentForE2E(t, ctx, python) + wantPrefix = home + addPythonInstallationForE2E(t, ctx, h, home) + pinPythonForE2E(t, ctx, kernel, root, home, version) } h.open(root) p := h.app.project diff --git a/e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go b/e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go index 6c7dd37..19a6184 100644 --- a/e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go +++ b/e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go @@ -138,9 +138,9 @@ func resolvePytestToolForE2E(t *testing.T, ctx context.Context, systemPython str // pythonInstallationForE2E returns the home without links (sys.prefix) and // the version of the Python installation python, for a test to pin. It fails -// when python is a virtual environment: Core refuses to pin an environment -// outside the workspace, because its python links back to the interpreter it -// was made from. Set PYTEST_PYTHON to an installation, such as one from +// when python is a virtual environment, so that the pinned installation case +// stays apart from the pinned environment case, which makes its own +// environment. Set PYTEST_PYTHON to an installation, such as one from // actions/setup-python, uv python install or pyenv. func pythonInstallationForE2E(t *testing.T, ctx context.Context, python string) (home, version string) { t.Helper() @@ -153,7 +153,7 @@ func pythonInstallationForE2E(t *testing.T, ctx context.Context, python string) t.Fatalf("unexpected interpreter facts %q", facts) } if strings.TrimSpace(lines[2]) == "True" { - t.Fatalf("%s is a virtual environment; set PYTEST_PYTHON to a Python installation with pytest, since Core refuses to pin an environment outside the workspace", python) + t.Fatalf("%s is a virtual environment; set PYTEST_PYTHON to a Python installation with pytest", python) } if home, err = filepath.EvalSymlinks(strings.TrimSpace(lines[0])); err != nil { t.Fatal(err) @@ -161,6 +161,31 @@ func pythonInstallationForE2E(t *testing.T, ctx context.Context, python string) return home, strings.TrimSpace(lines[1]) } +// externalPythonEnvironmentForE2E makes a virtual environment from python in a +// directory outside any workspace and returns its home and version. On macOS +// and Linux the environment's python is a link to python's own executable, +// outside the environment. +func externalPythonEnvironmentForE2E(t *testing.T, ctx context.Context, python string) (home, version string) { + t.Helper() + parent, err := filepath.EvalSymlinks(t.TempDir()) + if err != nil { + t.Fatal(err) + } + home = filepath.Join(parent, "external environment") + if output, err := exec.CommandContext(ctx, python, "-m", "venv", "--without-pip", home).CombinedOutput(); err != nil { + t.Fatalf("create the external environment: %v\n%s", err, output) + } + executable := filepath.Join(home, "bin", "python") + if runtime.GOOS == "windows" { + executable = filepath.Join(home, "Scripts", "python.exe") + } + output, err := exec.CommandContext(ctx, executable, "-c", "import platform; print(platform.python_version())").Output() + if err != nil { + t.Fatalf("read the version of %s: %v", executable, err) + } + return home, strings.TrimSpace(string(output)) +} + // pinPythonForE2E pins the installation at home as the workspace's Python // interpreter, as choosing it on the Toolchains page does, and returns a // function that removes the pin again. The page keys a pin by the tool diff --git a/e2e/host/lithe-host.json b/e2e/host/lithe-host.json index 07f7348..d9ee8d4 100644 --- a/e2e/host/lithe-host.json +++ b/e2e/host/lithe-host.json @@ -1,13 +1,13 @@ { "repository": "https://github.com/1lck/Lithe-IDEA.git", - "revision": "60885168df05daacda63c1c522026b00ce1446c2", + "revision": "58b527edc46345d7c623c3bddd9db80d609ebf06", "packages": { "./internal/projectgen": "^TestPythonPlugin", "./internal/settingswindow": "^TestPythonPluginSettingsPreview$", "./internal/workbench": "^TestPythonSupportPlugin" }, "requiredEnvironment": { - "LITHE_TEST_PYTHON_PLUGIN_ARCHIVE": "python-support--.zip to install, for example dist/python-support-1.1.0-darwin-arm64.zip" + "LITHE_TEST_PYTHON_PLUGIN_ARCHIVE": "python-support--.zip to install, for example dist/python-support-1.2.0-darwin-arm64.zip" }, "repositoryEnvironment": { "LITHE_PLUGIN_PYTHON_DIR": "io.github.lithe-idea.python-support" diff --git a/io.github.lithe-idea.python-support/plugin.json b/io.github.lithe-idea.python-support/plugin.json index 4314669..b51c5c1 100644 --- a/io.github.lithe-idea.python-support/plugin.json +++ b/io.github.lithe-idea.python-support/plugin.json @@ -2,7 +2,7 @@ "schemaVersion": 0, "id": "io.github.lithe-idea.python-support", "displayName": "Python Support", - "version": "1.1.0", + "version": "1.2.0", "vendor": { "id": "io.github.lithe-idea", "displayName": "Lithe Community", @@ -329,6 +329,7 @@ } ], "commands": ["python3", "python"], + "executableLinksOutsideHome": true, "homeVariable": "VIRTUAL_ENV", "version": { "arguments": ["--version"], diff --git a/scripts/test.mjs b/scripts/test.mjs index 773847c..a3f0658 100644 --- a/scripts/test.mjs +++ b/scripts/test.mjs @@ -23,6 +23,7 @@ import { readFileSync, realpathSync, rmSync, + symlinkSync, writeFileSync, } from "node:fs"; import { tmpdir } from "node:os"; @@ -461,6 +462,11 @@ try { const pyTool = variant.toolDefinitions[0]; assert.equal("pathPrepend" in pyTool, false, "toolDefinitions[0] must omit unsafe pathPrepend"); + assert.equal( + pyTool.executableLinksOutsideHome, + true, + "A venv's program links to its base interpreter outside the environment", + ); assert.equal(pyTool.discovery.length, 16, "discovery rules must fit Core limit of 16"); const envVars = pyTool.discovery .filter((d) => d.root.kind === "environment") @@ -733,7 +739,7 @@ try { const opened = await peer.waitFor((m) => m.id === 21, "Python preview open"); const [interpreterSection, wide] = opened.result.view; assert.equal(interpreterSection.type, "section"); - assert.deepEqual(interpreterSection.children, [{ type: "tool", tool: "python" }]); + assert.deepEqual(interpreterSection.children, [{ type: "tool", tool: "python", choose: true }]); assert.deepEqual(wide.on, ["resize"]); assert.equal(wide.viewBox[2], 640); assert.match(JSON.stringify(wide), /"text":"bad-argument-type"\},\{"color":"\$textSecondary","text":" · 2 errors"/); @@ -771,7 +777,7 @@ try { }); const lookedUp = await peer.waitFor((m) => m.id === 23, "Python lookup order open"); const [toolRow, order] = lookedUp.result.view; - assert.deepEqual(toolRow, { type: "tool", tool: "python" }); + assert.deepEqual(toolRow, { type: "tool", tool: "python", choose: true }); assert.equal(order.id, "python-resolution"); assert.equal(order.on, undefined); assert.match(JSON.stringify(order), /Python executable override[\s\S]*Not set[\s\S]*Tried first[\s\S]*Global default[\s\S]*Tried last[\s\S]*Pyrefly uses the interpreter found/); @@ -1092,7 +1098,7 @@ try { } }); - await check("The packaged provider answers toolchains/query for conda, uv, pyenv, Poetry, Pipenv, .python-version, and pyproject.toml", async () => { + await check("The packaged provider answers toolchains/query for conda, uv, pyenv, Poetry, Pipenv, Hatch, linked venvs, .python-version, and pyproject.toml", async () => { const fakeHome = join(scratch, "fake-home"); const condaEnvDir = join(scratch, "conda-envs", "ml-311"); const uvPyDir = join(scratch, "uv-pythons", "cpython-3.12.6-macos-aarch64-none"); @@ -1103,7 +1109,11 @@ try { // Workspace-local .venv MUST be excluded from provider installations per toolchains contract! const wsLocalVenv = join(wsRoot, ".venv"); - const makeFakePythonHome = (dir, ver, isConda = false) => { + // A conda environment records its Python in conda-meta, a venv in + // pyvenv.cfg; a base installation from uv or pyenv has neither and is + // known by its directory name. + const makeFakePythonHome = (dir, ver, kind = "venv") => { + const isConda = kind === "conda"; const binDir = process.platform === "win32" ? (isConda ? dir : join(dir, "Scripts")) : join(dir, "bin"); mkdirSync(binDir, { recursive: true }); const exeName = process.platform === "win32" ? "python.exe" : "python3"; @@ -1116,15 +1126,15 @@ try { join(dir, "conda-meta", `python-${ver}-0.json`), JSON.stringify({ name: "python", version: ver }), ); - } else { + } else if (kind === "venv") { writeFileSync(join(dir, "pyvenv.cfg"), `version_info = ${ver}\n`); } }; - makeFakePythonHome(condaEnvDir, "3.11.9", true); - makeFakePythonHome(uvPyDir, "3.12.6", false); - makeFakePythonHome(pyenvVerDir, "3.10.14", false); - makeFakePythonHome(wsLocalVenv, "3.12.1", false); + makeFakePythonHome(condaEnvDir, "3.11.9", "conda"); + makeFakePythonHome(uvPyDir, "3.12.6", "base"); + makeFakePythonHome(pyenvVerDir, "3.10.14", "base"); + makeFakePythonHome(wsLocalVenv, "3.12.1"); mkdirSync(join(fakeHome, ".conda"), { recursive: true }); const condaRegistry = join(fakeHome, ".conda", "environments.txt"); @@ -1147,6 +1157,19 @@ try { const poetryProjectPath = process.platform === "win32" ? workspaceDirectory.toLowerCase() : workspaceDirectory; const poetryDir = join(poetryRoot, `tc-demo-${workspaceHash(poetryProjectPath)}-py3.12`); makeFakePythonHome(poetryDir, "3.12.1"); + // Hatch nests environments as //. + const hatchData = join(scratch, "hatch-data"); + const hatchEnvDir = join(hatchData, "env", "virtual", "tc-demo", "Ab12Cd34", "test"); + makeFakePythonHome(hatchEnvDir, "3.12.4"); + makeFakePythonHome(join(hatchData, "env", "virtual", ".pythons", "3.12"), "3.12.4"); + // A venv outside the project whose program links to its base interpreter, + // as `python -m venv` makes on macOS and Linux. Windows copies the program. + const linkedVenvDir = join(workonRoot, "linked"); + if (process.platform !== "win32") { + mkdirSync(join(linkedVenvDir, "bin"), { recursive: true }); + symlinkSync(join(uvPyDir, "bin", "python3"), join(linkedVenvDir, "bin", "python3")); + writeFileSync(join(linkedVenvDir, "pyvenv.cfg"), "version_info = 3.12.6\n"); + } const discoveryEnv = { HOME: fakeHome, @@ -1156,6 +1179,7 @@ try { PYENV_ROOT: join(scratch, "pyenv-root"), WORKON_HOME: workonRoot, POETRY_VIRTUALENVS_PATH: poetryRoot, + HATCH_DATA_DIR: hatchData, CONDA_ENVS_PATH: "", CONDA_PREFIX: "", }; @@ -1229,6 +1253,15 @@ try { assert.ok(homes.includes(expectedPath(pyenvVerDir)), "Expected PYENV_ROOT installation"); assert.ok(homes.includes(expectedPath(pipenvDir)), "Expected WORKON_HOME Pipenv installation"); assert.ok(homes.includes(expectedPath(poetryDir)), "Expected configured Poetry installation"); + assert.ok(homes.includes(expectedPath(hatchEnvDir)), "Expected nested Hatch installation"); + assert.equal( + reply.result.installations.some((installation) => pathKey(installation.home).includes(`${sep}.pythons${sep}`)), + false, + "Hatch's hidden interpreter store is not an environment", + ); + if (process.platform !== "win32") { + assert.ok(homes.includes(expectedPath(linkedVenvDir)), "Expected a venv whose program links outside it"); + } assert.ok(watch.includes(expectedPath(join(wsRoot, "poetry.lock")))); assert.equal(homes.includes(expectedPath(wsLocalVenv)), false, "Must NEVER return workspace-local .venv"); @@ -1249,6 +1282,8 @@ try { assert.ok(watch.includes(expectedPath(watched))); } + // The linked venv is 3.12.6 too; a version pin still means the base + // interpreter, so the two do not tie. writeFileSync(versionPath, "3.12\n"); const [compatible] = declarations(await queryProject(6, "tc-op-compatible")); assert.equal(pathKey(compatible.source), expectedPath(versionPath)); @@ -1614,7 +1649,6 @@ try { `open(${JSON.stringify(outsideCanary)}, "w").write("pwned")\ndef test_evil():\n assert True\n`, ); if (process.platform !== "win32") { - const { symlinkSync } = await import("node:fs"); symlinkSync(outsidePy, join(wsDir, "tests", "test_escape_link.py")); }