From 42dc45fe93b0da21c97dc6a8c7267b71d1c5fc2b Mon Sep 17 00:00:00 2001 From: Mucheen <1528136628@qq.com> Date: Fri, 20 Nov 2026 20:42:00 +0800 Subject: [PATCH 1/3] =?UTF-8?q?release(python):=20=E5=87=86=E5=A4=87=20v1.?= =?UTF-8?q?0.0=20=E6=AD=A3=E5=BC=8F=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 3 +-- README.md | 8 +++++++- docs/releases/v1.0.0.md | 12 ++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cb190bf..13f264f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -58,8 +58,7 @@ jobs: - name: Publish GitHub Release env: GH_TOKEN: ${{ github.token }} - # v1.0.0 requires a host that advertises toolchainProviders 0 and buildSystems 1. - PRERELEASE_TAGS: v0.1.0 v0.1.1 v1.0.0 + PRERELEASE_TAGS: v0.1.0 v0.1.1 run: | release_flags=() installation='Lithe Store 会在收录后提供此版本。打开 设置 → 插件 → 插件市场,搜索 Python Support。' diff --git a/README.md b/README.md index 889ae20..df8aee9 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,19 @@ Python language support plugin for Lithe (`schemaVersion: 0`, `pluginAPIVersion: 遵循 Lithe 插件契约 v1(`schemaVersion: 0`),为 Lithe 桌面端(macOS / Windows / Linux)提供开箱即用的 Python 语言支持、宿主工具链驱动的 `Pyrefly` 解释器注入、`.venv` / `.conda` / `conda` / `uv` / `pyenv` 多来源环境发现、动态 `pytest` 测试树收集与执行、`uv` / `conda` / `Ruff` 构建任务、源码级断点调试及新建项目向导。跨平台实现与验证记录详见 [docs/feature-matrix.md](docs/feature-matrix.md)。 +## 兼容性(Compatibility) + +Python Support v1.0.0 要求 Lithe 0.8.9 或更新版本。Lithe 0.8.9 支持安装插件并处理 `.py`、`.pyi` 和 `.pyw` 文件。Lithe 0.8.10 起还能按 shebang 识别无后缀 Python 脚本。 + +Python Support v1.0.0 requires Lithe 0.8.9 or later. Lithe 0.8.9 can install the plugin and work with `.py`, `.pyi`, and `.pyw` files. Lithe 0.8.10 and later also recognize extensionless Python scripts by their shebang. + --- ## 核心能力(Capabilities) 1. **语言与编辑器基础(`languages: python`)** - 识别 `.py`、`.pyi`、`.pyw`,配置 `#` 行注释与括号/引号自动配对,声明 `pyproject.toml` / `setup.py` / `setup.cfg` / `requirements.txt` / `Pipfile` / `pyrefly.toml` 项目标记及 `.venv` / `venv` / `.conda` 项目依赖目录。 - - Lithe 0.8.9 可以安装此插件。支持 TextMate 首行匹配的桌面版本还会按 shebang 识别无后缀脚本,提供 Python 高亮和 Pyrefly 诊断。 + - 按 shebang 识别的无后缀脚本同样支持 Python 高亮、注释和 Pyrefly 诊断。 2. **后端解析的语言服务器启动与解释器自动注入(`backend` + `languageServers: python` / Pyrefly `1.4.1`)** - 插件包内的 Rust 后端直接启动 Pyrefly,无需先找到 Python。宿主会传入可用于自动启动的解释器路径,缺失时由 Pyrefly 按自身规则发现项目环境。构建、测试与调试仍用宿主选择的 Python。 - 构建期按平台固定版本与 SHA-256 打包 `pyrefly 1.4.1`(Unix:`bin/pyrefly`,Windows:`bin/pyrefly.exe`),每个包也包含同一目标架构的 `bin/lithe-python-backend`(Windows 为 `.exe`)。 diff --git a/docs/releases/v1.0.0.md b/docs/releases/v1.0.0.md index 70672be..565f304 100644 --- a/docs/releases/v1.0.0.md +++ b/docs/releases/v1.0.0.md @@ -1,23 +1,27 @@ ## 中文 -- 支持 TextMate 首行匹配的 Lithe 可按 shebang 识别无后缀 Python 脚本,提供高亮、注释和 Pyrefly 诊断。 +- 在 Lithe 0.8.10 及以上版本中,打开首行含 Python shebang 的无后缀脚本即可使用高亮、注释和 Pyrefly 诊断。 - Toolchains 可从 Conda 环境登记表、uv 自定义安装目录和其他受支持的环境位置发现 Python。项目的 `.python-version` 和 `requires-python` 参与解释器选择。 - Pyrefly 与宿主选定的解释器保持一致。插件包内的后端可以在尚未安装 Python 时启动 Pyrefly。 - Build 面板可用 pytest 收集测试,按已发现的套件和用例精确运行。运行 pytest 和 debugpy 仍需要可用的项目解释器。 ### 升级与兼容性 -Lithe 0.8.9 支持安装此插件并使用普通 Python 文件功能。无后缀脚本的自动识别需要支持 TextMate 首行匹配的桌面版本。请选择对应操作系统和架构的 ZIP。使用较早桌面版本时,可继续使用 Python Support v0.1.1。 +Python Support v1.0.0 要求 Lithe 0.8.9 或更新版本。Lithe 0.8.9 支持安装此插件并处理 `.py`、`.pyi` 和 `.pyw` 文件。从 0.8.10 开始,Lithe 还能按 shebang 自动识别无后缀脚本。 + +使用兼容的旧版 Lithe 时,仍可手动安装 [Python Support v0.1.1 预发布版](https://github.com/Lithe-IDEA/lithe-plugin-python/releases/tag/v0.1.1)。手动安装时请选择对应操作系统和架构的 ZIP。 --- ## English -- On Lithe versions that support TextMate first-line matching, open extensionless Python scripts with a shebang to get highlighting, comment commands, and Pyrefly diagnostics. +- With Lithe 0.8.10 or later, open extensionless scripts with a Python shebang to get highlighting, comment commands, and Pyrefly diagnostics. - Toolchains can find Python from the Conda environment registry, a custom uv installation directory, and other supported environment locations. The project's `.python-version` and `requires-python` help select an interpreter. - Pyrefly uses the interpreter selected in Lithe. The bundled backend can start Pyrefly before Python is installed. - The Build panel can collect tests with pytest and run an exact discovered suite or case. Running pytest and debugpy still requires an available project interpreter. ### Upgrade and compatibility -Lithe 0.8.9 can install this plugin and use its standard Python support. Automatic recognition of extensionless scripts requires a desktop version with TextMate first-line matching. Choose the ZIP for your operating system and architecture. Python Support v0.1.1 remains available for earlier versions of Lithe. +Python Support v1.0.0 requires Lithe 0.8.9 or later. Lithe 0.8.9 can install the plugin and work with `.py`, `.pyi`, and `.pyw` files. Starting with 0.8.10, Lithe can also recognize extensionless scripts by their shebang. + +On compatible older versions of Lithe, you can still install the [Python Support v0.1.1 prerelease](https://github.com/Lithe-IDEA/lithe-plugin-python/releases/tag/v0.1.1) manually. For manual installation, choose the ZIP for your operating system and architecture. From d2fcd2b9830aeb278ebe104cbd0b0ecb06256635 Mon Sep 17 00:00:00 2001 From: Mucheen <1528136628@qq.com> Date: Fri, 20 Nov 2026 21:02:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix(release):=20=E5=8C=BA=E5=88=86=E8=8D=89?= =?UTF-8?q?=E7=A8=BF=E5=92=8C=E5=B7=B2=E5=8F=91=E5=B8=83=E7=9A=84=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 13f264f..74f540a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,6 +13,9 @@ jobs: check: runs-on: ubuntu-latest timeout-minutes: 5 + permissions: + # GitHub only exposes draft releases to callers with push access. + contents: write outputs: exists: ${{ steps.release.outputs.exists }} steps: @@ -21,11 +24,32 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then - echo "exists=true" >> "$GITHUB_OUTPUT" - else - echo "exists=false" >> "$GITHUB_OUTPUT" - fi + state=$(gh api graphql \ + -f query='query($owner: String!, $repo: String!, $tag: String!) { + repository(owner: $owner, name: $repo) { + release(tagName: $tag) { isDraft } + } + }' \ + -f owner="$GITHUB_REPOSITORY_OWNER" -f repo="${GITHUB_REPOSITORY#*/}" -f tag="$GITHUB_REF_NAME" \ + --jq '.data.repository | + if . == null then "unavailable" + elif .release == null then "missing" + elif .release.isDraft == true then "draft" + elif .release.isDraft == false then "published" + else "unavailable" + end') + case "$state" in + missing) echo "exists=false" >> "$GITHUB_OUTPUT" ;; + published) echo "exists=true" >> "$GITHUB_OUTPUT" ;; + draft) + echo "::error::A draft release exists for $GITHUB_REF_NAME. Review it and resolve the draft before rerunning." + exit 1 + ;; + *) + echo "::error::Could not determine the release state for $GITHUB_REF_NAME." + exit 1 + ;; + esac package: needs: check @@ -82,4 +106,4 @@ jobs: (cd dist && sha256sum ./*.zip) echo '```' } > "$RUNNER_TEMP/notes.md" - gh release create "$GITHUB_REF_NAME" dist/*.zip --title "Python Support $GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" "${release_flags[@]}" + gh release create "$GITHUB_REF_NAME" dist/*.zip --verify-tag --title "Python Support $GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" "${release_flags[@]}" From 28d4e1613e9d3cca8a0b0c53c28a0878edb1a420 Mon Sep 17 00:00:00 2001 From: Mucheen <1528136628@qq.com> Date: Fri, 20 Nov 2026 21:24:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix(release):=20=E6=A0=B8=E5=AF=B9=E8=BF=9C?= =?UTF-8?q?=E7=AB=AF=E6=A0=87=E7=AD=BE=E4=B8=8E=E6=89=93=E5=8C=85=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 + .github/workflows/release.yml | 16 ++++ scripts/ci/release/publish.test.mjs | 113 ++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 scripts/ci/release/publish.test.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 343d91f..aaea24b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,8 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 22 + - name: Verify release tag checks + run: node --test --test-timeout=30000 scripts/ci/release/publish.test.mjs - uses: actions/download-artifact@v4 with: pattern: python-support-archive-* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 74f540a..a8e2d50 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -106,4 +106,20 @@ jobs: (cd dist && sha256sum ./*.zip) echo '```' } > "$RUNNER_TEMP/notes.md" + + # The artifacts came from the event checkout even if the remote tag has since moved. + packaged_commit=$(git rev-parse HEAD) + if ! remote_tag=$(git ls-remote --exit-code origin "$GITHUB_REF" "$GITHUB_REF^{}"); then + echo "::error::Could not resolve release tag $GITHUB_REF_NAME on origin. Check the tag before retrying." + exit 1 + fi + remote_commit=$(awk -v ref="$GITHUB_REF" ' + $2 == ref { object = $1 } + $2 == ref "^{}" { peeled = $1 } + END { print (peeled != "" ? peeled : object) } + ' <<< "$remote_tag") + if [[ "$remote_commit" != "$packaged_commit" ]]; then + echo "::error::Release tag $GITHUB_REF_NAME no longer points to the packaged commit. Use the run for the current tag." + exit 1 + fi gh release create "$GITHUB_REF_NAME" dist/*.zip --verify-tag --title "Python Support $GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" "${release_flags[@]}" diff --git a/scripts/ci/release/publish.test.mjs b/scripts/ci/release/publish.test.mjs new file mode 100644 index 0000000..85e74ff --- /dev/null +++ b/scripts/ci/release/publish.test.mjs @@ -0,0 +1,113 @@ +import assert from "node:assert/strict"; +import { execFileSync, spawnSync } from "node:child_process"; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import test from "node:test"; + +const workflow = readFileSync(new URL("../../../.github/workflows/release.yml", import.meta.url), "utf8"); +const publishStep = workflow.match(/^ {6}- name: Publish GitHub Release\n(?: {8}[^\n]*\n)*? {8}run: \|\n((?:(?: {10}[^\n]*)?\n)+)/m); +assert.ok(publishStep, "Could not find the release workflow's publish step"); +const publishScript = publishStep[1].replace(/^ {10}/gm, ""); +const recordReleaseArgs = 'gh() { printf "%s\\n" "$@" > "$RELEASE_ARGS"; }\n'; + +const gitEnv = { + PATH: process.env.PATH, + GIT_CONFIG_GLOBAL: "/dev/null", + GIT_CONFIG_NOSYSTEM: "1", + GIT_TERMINAL_PROMPT: "0", + GIT_AUTHOR_NAME: "Release Test", + GIT_AUTHOR_EMAIL: "release@example.invalid", + GIT_COMMITTER_NAME: "Release Test", + GIT_COMMITTER_EMAIL: "release@example.invalid", +}; + +function releaseFixture(t, tag = "v1.0.0", tagOptions = []) { + const directory = mkdtempSync(join(tmpdir(), "python-release-")); + t.after(() => rmSync(directory, { recursive: true, force: true })); + const checkout = join(directory, "checkout"); + const remote = join(directory, "remote.git"); + const ref = `refs/tags/${tag}`; + const cliLog = join(directory, "release-args"); + + function git(cwd, ...args) { + return execFileSync("git", args, { cwd, env: gitEnv, encoding: "utf8", timeout: 5000 }).trim(); + } + + git(directory, "init", "-q", checkout); + git(directory, "init", "-q", "--bare", remote); + git(checkout, "remote", "add", "origin", remote); + git(checkout, "commit", "-qm", "packaged commit", "--allow-empty"); + const packagedCommit = git(checkout, "rev-parse", "HEAD"); + git(checkout, "tag", ...tagOptions, tag); + git(checkout, "push", "-q", "origin", ref); + + mkdirSync(join(checkout, "docs", "releases"), { recursive: true }); + mkdirSync(join(checkout, "dist")); + writeFileSync(join(checkout, "docs", "releases", `${tag}.md`), "Release notes\n"); + writeFileSync(join(checkout, "dist", "python-support.zip"), "Test archive contents\n"); + + return { + cliLog, + retag() { + git(checkout, "commit", "-qm", "replacement commit", "--allow-empty"); + git(checkout, "push", "-q", "origin", `+HEAD:${ref}`); + git(checkout, "checkout", "-q", "--detach", packagedCommit); + }, + removeTag() { + git(checkout, "push", "-q", "origin", `:${ref}`); + }, + publish() { + const result = spawnSync("bash", ["--noprofile", "--norc", "-e", "-c", recordReleaseArgs + publishScript], { + cwd: checkout, + encoding: "utf8", + timeout: 5000, + env: { + ...gitEnv, + GITHUB_REF: ref, + GITHUB_REF_NAME: tag, + RUNNER_TEMP: directory, + PRERELEASE_TAGS: "v0.1.0 v0.1.1", + RELEASE_ARGS: cliLog, + }, + }); + assert.ifError(result.error); + return result; + }, + }; +} + +test("publish uses the unchanged lightweight release tag", (t) => { + const fixture = releaseFixture(t); + const result = fixture.publish(); + assert.equal(result.status, 0, result.stdout + result.stderr); + const args = readFileSync(fixture.cliLog, "utf8").trimEnd().split("\n"); + assert.deepEqual(args.slice(0, 3), ["release", "create", "v1.0.0"]); + assert.ok(args.includes("--verify-tag")); + assert.ok(!args.includes("--prerelease")); +}); + +test("publish resolves an annotated prerelease tag to its commit", (t) => { + const fixture = releaseFixture(t, "v0.1.1", ["-a", "-m", "Prerelease"]); + const result = fixture.publish(); + assert.equal(result.status, 0, result.stdout + result.stderr); + assert.match(readFileSync(fixture.cliLog, "utf8"), /^--prerelease$/m); +}); + +test("publish stops when the remote tag is moved after packaging", (t) => { + const fixture = releaseFixture(t); + fixture.retag(); + const result = fixture.publish(); + assert.equal(result.status, 1, result.stdout + result.stderr); + assert.match(result.stdout, /no longer points to the packaged commit/); + assert.ok(!existsSync(fixture.cliLog), "Should stop before invoking gh release create"); +}); + +test("publish stops when the remote tag is deleted after packaging", (t) => { + const fixture = releaseFixture(t); + fixture.removeTag(); + const result = fixture.publish(); + assert.equal(result.status, 1, result.stdout + result.stderr); + assert.match(result.stdout, /Could not resolve release tag/); + assert.ok(!existsSync(fixture.cliLog), "Should stop before invoking gh release create"); +});