From e87e1e2678ad9ca015cc6c37c6902078781e56a7 Mon Sep 17 00:00:00 2001 From: Qiheng He Date: Sat, 14 Nov 2026 00:30:34 +0800 Subject: [PATCH 1/4] fix: match partial versions by release number releaseOf read a source suffix as part of the release. A name such as 3.12.8-opt ends in t, so it looked free-threaded and `vfox use python@3.12` could not select it; 3.13.1t-uv was never selected by 3.13t either. find_installed, which resolves .python-version, matched a plain 3.13 against 3.13.1t and a plain 3.14 against the pre-release 3.14.0a4. The same file could therefore select a different version from vfox use. A release line now goes through find_release, as PreUse does. Exact versions and prefixes such as 3.12.8 still reach linked names. --- lib/python_version.lua | 30 +++++++++++++++++++----------- tests/parse_legacy_file_test.lua | 11 +++++++++++ tests/partial_version_test.lua | 23 +++++++++++++++++++++++ 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/lib/python_version.lua b/lib/python_version.lua index cd3251c..90e2f7e 100644 --- a/lib/python_version.lua +++ b/lib/python_version.lua @@ -116,11 +116,13 @@ function python_version.parse_request(text) return value end ---- Finds the installed name a request selects. The exact name wins; then the ---- newest installed version that starts with the request. A request of ---- "system" takes the newest linked system Python. When two names share a ---- version, a bare install comes before a source-suffixed one, as vfox's own ---- matching does. +--- Finds the installed name a request selects. The exact name wins. A release +--- line such as "3.13" is resolved as find_release resolves it for vfox use, so +--- it never selects a free-threaded or pre-release name. Any other request is +--- matched as a prefix, so an exact version such as "3.12.8" still selects a +--- linked "3.12.8-system". A request of "system" takes the newest linked system +--- Python. When two names share a version, a bare install comes before a +--- source-suffixed one, as vfox's own matching does. function python_version.find_installed(installed, request) if type(request) ~= "string" or request == "" then return nil @@ -140,6 +142,10 @@ function python_version.find_installed(installed, request) return request end + if python_version.is_partial(request) then + return python_version.find_release(installed, request) + end + local best, best_rank for name in pairs(installed) do if name:sub(1, #request) == request then @@ -188,13 +194,15 @@ function python_version.is_partial(request) return request:match("^%d+$") ~= nil or request:match("^%d+%.%d+t?$") ~= nil end ---- Splits a name into the text before a free-threaded `t` suffix, whether the ---- name has that suffix, and whether it is a pre-release. "3.13.18t" is ---- free-threaded; "3.16.0a2" is a pre-release, recognised by a letter right ---- after a digit. A source suffix such as "-system" is neither. +--- Splits a name into its release, whether the release is free-threaded, and +--- whether it is a pre-release. The source suffix (-system, -opt, -uv, ...) is +--- not part of the release, so it is removed first: "3.12.8-opt" is not +--- free-threaded, and "3.13.1t-uv" is. "3.13.18t" is free-threaded; "3.16.0a2" +--- is a pre-release, recognised by a letter right after a digit. local function releaseOf(name) - local free = name:sub(-1) == "t" - local release = free and name:sub(1, -2) or name + local base = name:match("^[^-]+") or name + local free = base:sub(-1) == "t" + local release = free and base:sub(1, -2) or base return release, free, release:find("%d%a") ~= nil end diff --git a/tests/parse_legacy_file_test.lua b/tests/parse_legacy_file_test.lua index 174fcfb..40d4ebc 100644 --- a/tests/parse_legacy_file_test.lua +++ b/tests/parse_legacy_file_test.lua @@ -48,6 +48,17 @@ assert(result.version == "3.12.8t-system", tostring(result.version)) result = parse("python-version-system", { "3.11.9-system", "3.12.3-system" }) assert(result.version == "3.12.3-system", tostring(result.version)) +-- A release line follows the rule vfox use follows: 3.12 in a .python-version +-- file never selects a free-threaded or pre-release install. +result = parse("python-version", { "3.12.9t", "3.12.8" }) +assert(result.version == "3.12.8", tostring(result.version)) + +result = parse("python-version", { "3.12.17a1" }) +assert(result.version == nil or result.version == "", tostring(result.version)) + +result = parse("python-version", { "3.12.8-opt" }) +assert(result.version == "3.12.8-opt", tostring(result.version)) + result = parse("python-version-pypy", { "3.10.14" }) assert(result.version == nil or result.version == "", tostring(result.version)) diff --git a/tests/partial_version_test.lua b/tests/partial_version_test.lua index de7ec9f..cd406d3 100644 --- a/tests/partial_version_test.lua +++ b/tests/partial_version_test.lua @@ -83,6 +83,29 @@ for _, case in ipairs(cases) do assert(got == case[2], case[1] .. " selected " .. tostring(got) .. ", want " .. tostring(case[2])) end +-- A source suffix is not part of the release. -opt does not make a name +-- free-threaded, and -uv keeps a free-threaded release free-threaded. +local linked = set({ "3.12.8-opt", "3.13.1t-uv", "3.14.0a4t-uv" }) +local linkedCases = { + { "3.12", "3.12.8-opt" }, + { "3.13", nil }, -- 3.13.1t-uv is free-threaded, so a plain request skips it + { "3.13t", "3.13.1t-uv" }, + { "3.14t", nil }, -- 3.14.0a4t-uv is a pre-release +} +for _, case in ipairs(linkedCases) do + local got = python_version.find_release(linked, case[1]) + assert(got == case[2], case[1] .. " selected " .. tostring(got) .. ", want " .. tostring(case[2])) +end + +-- .python-version resolves a release line the way vfox use does, while an +-- exact version or a bare prefix still reaches a linked name. +assert(python_version.find_installed(set({ "3.13.0", "3.13.1t" }), "3.13") == "3.13.0") +assert(python_version.find_installed(set({ "3.13.1t", "3.13.0" }), "3.13t") == "3.13.1t") +assert(python_version.find_installed(set({ "3.14.0a4" }), "3.14") == nil) +assert(python_version.find_installed(set({ "3.14.0a4" }), "3.14.0a4") == "3.14.0a4") +assert(python_version.find_installed(set({ "3.12.8-opt" }), "3.12") == "3.12.8-opt") +assert(python_version.find_installed(set({ "3.12.8-system" }), "3.12.8") == "3.12.8-system") + -- PreInstall: a partial request reads the version list, an exact one does not. local before = reads local package = plugin:PreInstall({ version = "3.12" }) From 5afb6af13ad227850cc835a6f32b433da01a3fc2 Mon Sep 17 00:00:00 2001 From: Qiheng He Date: Sat, 14 Nov 2026 00:30:34 +0800 Subject: [PATCH 2/4] docs: update documentation for v0.6.3 and the version matching fix Bring the English and zh-CN documentation up to date with v0.6.3, and record the version matching fix in the changelog. - changes: the Unreleased section for the matching fix; 0.6.3 replaces the stale Unreleased heading - platforms, versions: a Windows CPython without an installer stops in PreInstall before the download; the MSI and EXE install target is the python- directory - development: PreInstall, PreUse, Detect, the Windows container suite, the Windows CI job, the release workflow, and the .python-version matching rule - zh-CN: fix the registration key wording and the PreUninstall sentence --- docs/changes.md | 11 +++++++++++ docs/development.md | 40 ++++++++++++++++++++++++++++++--------- docs/platforms.md | 16 +++++++++------- docs/versions.md | 8 +++++--- docs/zh-CN/changes.md | 7 +++++++ docs/zh-CN/development.md | 34 ++++++++++++++++++++++----------- docs/zh-CN/platforms.md | 6 +++--- docs/zh-CN/versions.md | 7 ++++--- 8 files changed, 93 insertions(+), 36 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index 8f8f6f4..c690e28 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -4,6 +4,17 @@ ## Unreleased +- A partial version such as `python@3.12` now selects a linked install named + with `-opt`, such as `3.12.8-opt`, and `python@3.13t` selects a linked + free-threaded install, such as `3.13.1t-uv`. The source suffix is no longer + read as part of the release. +- A `.python-version` file that names a partial version such as `3.13` follows + the rule `vfox use` follows: it no longer selects a free-threaded (`t`) or + pre-release install. `3.13t` still selects a free-threaded install; a + pre-release needs its full name, such as `3.14.0a4`. + +## 0.6.3 + - When a source build fails, the error names the usual cause, a missing build dependency such as `zlib1g-dev`, and links to the platform notes. Without the zlib headers, `make install` fails in ensurepip. diff --git a/docs/development.md b/docs/development.md index 6b9c89b..6b1ed90 100644 --- a/docs/development.md +++ b/docs/development.md @@ -21,6 +21,7 @@ lib/python_version.lua version parsing and installed-name matching lib/detect_python.lua the Detect hook's sources and filtering tests/*_test.lua offline hook tests, run by vfox plugin test tests/windows_install_layouts.lua the Windows command paths, with stubbed processes +tests/e2e/ Go end-to-end suites for Linux and Windows; see e2e.md tests/fixtures/ .python-version files used by the legacy-file test bin/WiX/ the WiX tools used to extract Windows EXE installers .github/workflows/ test, lint, license, e2e and publish @@ -62,8 +63,10 @@ looked up. - `version = "latest"` is resolved to `Available({})[1].version`. The list is newest CPython first, so this can be a pre-release; GraalPy is selected by its full name. -- On Windows, a CPython version without an exact EXE or MSI for the architecture - is rejected before any download; `Available` should already have filtered it. +- On Windows, `Available` lists only the exact installer names on the download + page. PreInstall still sends a HEAD request for the EXE and then for the MSI, + and stops before any download when neither answers 200, with `Python + has no Windows installer on python.org`. - A GraalPy version is resolved against Oracle's release assets for the running platform. The hook returns the official archive URL and its SHA-256; Linux and macOS use `linux-*`/`macos-*` tarballs, Windows uses `windows-amd64.zip`. @@ -128,6 +131,11 @@ installation belongs to its owner, and missing packaging tools are normal for a system Python. `isLinkedPythonInstall` tests the `python-` link in the version directory with `test -L`. +On Windows the hook returns at once, so none of the checks above run there. On +Unix, an installation with no `bin` directory stops `vfox use` with an error +that names the problem and the `vfox uninstall` and `vfox install` commands to +run again, instead of printing "Now using" for a broken install. + ### EnvKeys - Unix: `PATH = ctx.path .. "/bin"`; for GraalPy, `/bin` with the @@ -155,9 +163,10 @@ already linked. Windows `Programs\Python`, `C:\Python*`, `C:\graalpy*`, the py launcher and the Store), - queries each interpreter once with `-E -s -c` and a one-line program, -- asks for `sys.version`, `sys.prefix`, `sys.base_prefix`, the real executable - and `sys.abiflags`, plus `__graalpython__.get_graalvm_version()` and the - Oracle/Community edition for GraalPy, +- asks for the Python version and implementation (`platform`), `sys.prefix`, + `sys.base_prefix`, the real executable and `sys.abiflags`, plus + `__graalpython__.get_graalvm_version()` and the Oracle/Community edition for + GraalPy, - skips PyPy and other implementations, virtual environments, vfox's own directory and root prefixes, - names the result `[-t]-` for CPython and @@ -182,6 +191,11 @@ The hook returns `{ version = name }` or `{}`. A version that is not installed selects nothing. With `strategy = "latest_installed"`, an unreadable or missing entry falls back to the newest installed name. +A partial version such as `3.13` in a `.python-version` file is resolved with +`find_release`, the function PreUse uses, so it never selects a free-threaded +or pre-release name. Other requests, such as `3.12.8`, are matched as a prefix, +so a linked `3.12.8-system` still counts. + ### windows_command `lib/windows_command.lua` builds `powershell -NoProfile -NonInteractive @@ -227,7 +241,10 @@ installs CPython from source, through the mirror, through uv-build and GraalPy, and also runs `vfox link --detect` and a project `.python-version` on the runner. The Windows package installs CPython and uv-build, installs GraalPy with PEP 514 registration, and checks `.python-version`. Both packages also -drive the same GraalPy checks in Docker containers through testcontainers-go. +run GraalPy checks in Docker containers: the Linux package through +testcontainers-go, the Windows package through the `docker` CLI, because +testcontainers-go creates a bridge network for every container and a Windows +engine has no bridge driver. See [E2E](e2e.md) for the layout and the local commands. Local commands: @@ -268,8 +285,9 @@ is missing. ## CI - `test.yml` runs the offline tests on `ubuntu-latest` and `windows-latest` with - vfox 1.1.0 (checksum-pinned), the GopherLua layouts on Linux, and the real - Windows MSI installation with paths full of spaces and shell characters. + vfox 1.1.0 (checksum-pinned), the GopherLua layouts on Linux, and a real + install of CPython 3.14.5 through the EXE installer on Windows, with paths full + of spaces and shell characters, driven by the released vfox 1.0.12. - `lint.yml` runs StyLua, LuaLS and actionlint. - `license.yml` runs the header check. - `e2e.yml` builds and installs real Pythons on Linux and Windows, including a @@ -282,7 +300,11 @@ Maintainers publish from **Actions → Plugin → Run workflow** on the default branch. Enter a stable plugin version without the `v` prefix; the shared workflow updates `metadata.lua`, creates the version commit and tag, and publishes the ZIP and manifest in this repository. Pull requests only run the -checks. Re-run the original failed job to resume a failed publication. +checks. Re-run the original failed job to resume a failed publication. No local +tag or release token is needed. Pushing a `v*` tag also runs the release job; it +is supported when `PLUGIN.version` in `metadata.lua` already matches the tag. The +workflows call the shared `version-fox/plugin-manifest-action` at `@v1`, and +updating that tool does not release this plugin. ## Adding a detection source diff --git a/docs/platforms.md b/docs/platforms.md index 0567726..38631c6 100644 --- a/docs/platforms.md +++ b/docs/platforms.md @@ -16,10 +16,11 @@ The CPython source build takes the pyenv tag and version list, clones pyenv at that tag, and runs its `python-build`. It needs a C toolchain and the headers Python links against. The Windows path downloads the python.org installer, -extracts its MSIs with the bundled WiX tools and runs `ensurepip`; it needs no -compiler. GraalPy is downloaded from Oracle's releases on every supported -platform and unpacked; it needs no compiler. Linux and macOS have amd64 and -arm64 assets; Windows only amd64. +installs its MSIs into the `python-` directory and runs `ensurepip`; for an EXE, +the bundled WiX tools extract the MSIs first. It needs no compiler. GraalPy is +downloaded from Oracle's releases on every supported platform and unpacked; it +needs no compiler. Linux and macOS have amd64 and arm64 assets; Windows only +amd64. ## Version coverage @@ -152,8 +153,9 @@ not. It checks in this order: 2. `python-.amd64.msi`, `python-.arm64.msi`, or, for 32-bit, `python-.msi`, when step 1 finds nothing. -If neither exists, the install fails with `No available installer found for -current version`. Two examples from python.org: +If neither exists, `vfox install` stops before it downloads anything, with +`Python has no Windows installer on python.org`. Two examples from +python.org: | Version | Published on python.org | Installer used | | --- | --- | --- | @@ -162,7 +164,7 @@ current version`. Two examples from python.org: - **EXE:** the file is a bundle. The plugin extracts its MSIs with the bundled WiX `dark.exe`, deletes `launcher.msi`, `path.msi`, `appendpath.msi` and - `pip.msi`, and installs the remaining MSIs into the version directory with + `pip.msi`, and installs the remaining MSIs into the `python-` directory with `msiexec /quiet /a TargetDir=`. It then runs `ensurepip`. Because the launcher, PATH and pip MSIs are skipped, a vfox install adds no `py.exe`, does not change `PATH`, and gets pip from `ensurepip`. diff --git a/docs/versions.md b/docs/versions.md index cc08aca..944996c 100644 --- a/docs/versions.md +++ b/docs/versions.md @@ -114,7 +114,9 @@ graalpy3.13-community-25.5.5 system ``` -- `3.12` selects the newest installed 3.12.x. +- `3.12` selects the newest installed 3.12.x, and like `vfox use` it never + selects a free-threaded (`t`) or pre-release install. `3.13t` selects a + free-threaded one; a pre-release needs its full name, such as `3.14.0a4`. - `cpython-3.12.8` selects `3.12.8`, or its linked `3.12.8-system` when only that is installed. - The `+freethreaded` form selects the `t` version. @@ -141,10 +143,10 @@ for 3.12.10, and only an MSI for 2.7.18. See [platforms.md](platforms.md#windows for the order of the checks. - `.exe` installers are extracted with the bundled WiX `dark.exe`. The MSIs - inside are installed into the version directory with `msiexec /quiet /a`; the + inside are installed into the `python-` directory with `msiexec /quiet /a`; the launcher, PATH and pip MSIs are skipped, and pip is bootstrapped with `ensurepip`. -- `.msi` installers (older releases) are installed into the version directory +- `.msi` installers (older releases) are installed into the `python-` directory with `msiexec /quiet /a`, and pip is bootstrapped with `ensurepip`. - Alias executables such as `python3.exe` and `python3.12.exe` are created next to `python.exe`, because the python.org installer normally creates them in a diff --git a/docs/zh-CN/changes.md b/docs/zh-CN/changes.md index 1bd4d52..ba09f6b 100644 --- a/docs/zh-CN/changes.md +++ b/docs/zh-CN/changes.md @@ -4,6 +4,13 @@ ## 未发布 +- 部分版本号(如 `python@3.12`)现在会选中名字带 `-opt` 的链接安装,如 `3.12.8-opt`; + `python@3.13t` 会选中自由线程的链接安装,如 `3.13.1t-uv`。来源后缀不再被当作版本的一部分。 +- `.python-version` 中的部分版本号(如 `3.13`)与 `vfox use` 遵循同一规则:不再选中自由线程 + (`t`)或预发布版。`3.13t` 仍然选中自由线程版本;预发布版请写完整名字,如 `3.14.0a4`。 + +## 0.6.3 + - 源码构建失败时,报错会指出常见原因:缺少构建依赖,例如 Debian/Ubuntu 上的 `zlib1g-dev`,并链接到 平台说明。没有 zlib 头文件时,`make install` 会在 ensurepip 步骤失败。 - Windows 上,如果 python.org 没有某个版本的安装包(如 3.12.12),`vfox install` 会在下载前 diff --git a/docs/zh-CN/development.md b/docs/zh-CN/development.md index 637d1cf..c57bd0c 100644 --- a/docs/zh-CN/development.md +++ b/docs/zh-CN/development.md @@ -21,6 +21,7 @@ lib/python_version.lua 版本解析和已安装名字匹配 lib/detect_python.lua Detect 钩子的来源和过滤 tests/*_test.lua 离线的钩子测试,由 vfox plugin test 运行 tests/windows_install_layouts.lua Windows 命令路径,进程调用用 stub 代替 +tests/e2e/ Go 端到端套件,覆盖 Linux 和 Windows,见 e2e.md tests/fixtures/ .python-version 测试用的文件 bin/WiX/ 解 Windows EXE 安装包用的 WiX 工具 .github/workflows/ test、lint、license、e2e 和 publish @@ -58,8 +59,9 @@ vfox 加载 `metadata.lua`,命令需要时调用相应的钩子,并向钩子 - `version = "latest"` 会解析成 `Available({})[1].version`。CPython 在列表最 前面、从新到旧排列,所以可能是预发布版;GraalPy 要用完整版本名。 -- Windows 上,CPython 没有当前架构的精确 EXE 或 MSI 时,在下载前就拒绝; - `Available` 应该已经过滤掉。 +- Windows 上,`Available` 只列出下载页里当前架构的精确安装包文件名。PreInstall 仍会先对 EXE、 + 再对 MSI 发 HEAD 请求;两者都没有返回 200 时,在任何下载开始前停止,并提示 + `Python <版本> has no Windows installer on python.org`。 - GraalPy 会到 Oracle 的发布资源里找当前平台的对应版本,返回官方压缩包地址和 SHA-256;Linux 和 macOS 用 `linux-*`/`macos-*` 的 tar.gz,Windows 用 `windows-amd64.zip`。GitHub API 被限流时,钩子会根据版本构造资源地址,并在 @@ -96,10 +98,10 @@ vfox 加载 `metadata.lua`,命令需要时调用相应的钩子,并向钩子 `ctx.main` 里有版本目录(`path`)和名字(`version`)。Windows 上,钩子只在 `VfoxManaged` 为 `1` 且注册的 `InstallPath` 仍指向该版本目录时,删除 `HKCU\Software\Python\VersionFox\`;如果 `VersionFox` company key 已经 -没有子项,也一并删除。即使 `VFOX_PYTHON_REGISTER_PY_LAUNCHER` 已取消,钩子 -仍会运行,所以即使 `VFOX_PYTHON_REGISTER_PY_LAUNCHER=0` 关闭了注册,卸载也不会留下旧项。 +没有子项,也一并删除。即使 `VFOX_PYTHON_REGISTER_PY_LAUNCHER=0` 关闭了注册,钩子 +仍会运行,所以卸载时不会留下旧的注册项。 -`lib/pep514.lua` 在读写信之前会识别 MSI 布局(`path/python.exe`)、uv-build +`lib/pep514.lua` 在读写注册项之前会识别 MSI 布局(`path/python.exe`)、uv-build 布局(`path/python-<版本>/python.exe`)和 GraalPy 布局 (`path/graalpy*-windows-amd64/bin/python.exe`)。 @@ -111,6 +113,9 @@ vfox 加载 `metadata.lua`,命令需要时调用相应的钩子,并向钩子 归它的主人所有,系统 Python 没有打包工具是正常的。`isLinkedPythonInstall` 用 `test -L` 检查版本目录里的 `python-<版本>` 链接。 +Windows 上钩子直接返回,上面的检查都不运行。Unix 上,安装目录没有 `bin` 时,`vfox use` +会报错,并给出先 `vfox uninstall` 再 `vfox install` 的命令,不再对损坏的安装显示 “Now using”。 + ### EnvKeys - Unix:`PATH = ctx.path .. "/bin"`;GraalPy 用 `/bin`,prefix 从 @@ -134,7 +139,7 @@ vfox 加载 `metadata.lua`,命令需要时调用相应的钩子,并向钩子 Homebrew、`/usr`、`/usr/local`、`/opt`、`~/graalpy*`、Windows 的 `Programs\Python`、`C:\Python*`、`C:\graalpy*`、py 启动器和 Store), - 用 `-E -s -c` 和一段单行程序询问每个解释器一次, -- 取 `sys.version`、`sys.prefix`、`sys.base_prefix`、真实可执行文件和 +- 取 Python 版本和实现(`platform` 模块)、`sys.prefix`、`sys.base_prefix`、真实可执行文件和 `sys.abiflags`,GraalPy 还取 `__graalpython__.get_graalvm_version()` 和 Oracle/Community 发行版, - 跳过 PyPy 等其他实现、虚拟环境、vfox 自己的目录和根目录, @@ -157,6 +162,10 @@ vfox 加载 `metadata.lua`,命令需要时调用相应的钩子,并向钩子 钩子返回 `{ version = name }` 或 `{}`。没安装的版本不选任何东西。 `strategy = "latest_installed"` 时,条目缺失或读不懂就退回到已安装的最新名字。 +部分版本号(如 `3.13`)在 `.python-version` 里用 `find_release` 解析,和 PreUse 用的是同一个函数, +所以不会选中自由线程或预发布版。其他请求(如 `3.12.8`)按前缀匹配,链接进来的 `3.12.8-system` +仍然算数。 + ### windows_command `lib/windows_command.lua` 生成 `powershell -NoProfile -NonInteractive @@ -193,8 +202,9 @@ local versions = plugin:Available({}) E2E 套件在 `tests/e2e` 里,使用 Go 编写。Linux 包在 runner 上安装 CPython 源码构建、镜像构建、uv-build 和 GraalPy,还会运行 `vfox link --detect` 和项目 的 `.python-version`。Windows 包安装 CPython 和 uv-build,安装带 PEP 514 注册的 -GraalPy,并检查 `.python-version`。两个包也通过 testcontainers-go 在 Docker -容器里跑同样的 GraalPy 检查。目录结构和本地命令见 +GraalPy,并检查 `.python-version`。两个包也在 Docker 容器里跑 GraalPy 检查:Linux 包通过 +testcontainers-go,Windows 包直接调用 `docker` 命令行,因为 testcontainers-go 会为每个容器 +创建 bridge 网络,而 Windows 引擎没有 bridge 驱动。目录结构和本地命令见 [端到端测试](e2e.md)。 本地命令: @@ -233,8 +243,8 @@ vfox 的全局变量,只关闭 `duplicate-set-field`(测试会有意替换 ` ## CI - `test.yml` 在 `ubuntu-latest` 和 `windows-latest` 上用 vfox 1.1.0(校验和 - 固定)跑离线测试,在 Linux 上跑 GopherLua 布局测试,并用带空格和 Shell - 字符的路径跑一次真实的 Windows MSI 安装。 + 固定)跑离线测试,在 Linux 上跑 GopherLua 布局测试,并用带空格和 Shell 字符的路径, + 由发布版 vfox 1.0.12 在 Windows 上通过 EXE 安装包真实安装一次 CPython 3.14.5。 - `lint.yml` 跑 StyLua、LuaLS 和 actionlint。 - `license.yml` 跑许可证头检查。 - `e2e.yml` 在 Linux 和 Windows 上真实构建、安装 Python,包括镜像、uv-build @@ -246,7 +256,9 @@ vfox 的全局变量,只关闭 `duplicate-set-field`(测试会有意替换 ` 维护者在默认分支的 **Actions → Plugin → Run workflow** 里发布。输入不带 `v` 的稳定插件版本号;共享工作流会更新 `metadata.lua`,创建版本提交和 tag,并在 本仓库发布 ZIP 和 manifest。Pull request 只跑检查。发布失败时重跑原来失败的 -任务即可继续。 +任务即可继续。不需要本地打 tag,也不需要额外的发布 token。推送 `v*` tag 同样会运行发布任务;只要 +`metadata.lua` 里的 `PLUGIN.version` 已与 tag 一致,就会正常发布。工作流调用的是共享的 +`version-fox/plugin-manifest-action`,固定在 `@v1`;升级该工具本身不会发布本插件。 ## 增加一个检测来源 diff --git a/docs/zh-CN/platforms.md b/docs/zh-CN/platforms.md index b072f2e..185c5c9 100644 --- a/docs/zh-CN/platforms.md +++ b/docs/zh-CN/platforms.md @@ -15,7 +15,7 @@ CPython 的源码构建取 pyenv 的 tag 和版本列表,把 pyenv 克隆到那个 tag,再运行 它的 `python-build`。它需要 C 工具链和 Python 链接的头文件。Windows 则下载 python.org -的安装包,用自带的 WiX 工具解开 MSI,再运行 `ensurepip`,不需要编译器。GraalPy +的安装包,把其中的 MSI 装进 `python-<版本>` 目录,再运行 `ensurepip`。EXE 需要先用自带的 WiX 工具解出 MSI。不需要编译器。GraalPy 在所有支持的平台上都从 Oracle 的发布页下载并解压,不需要编译器;Linux 和 macOS 有 amd64 和 arm64 资源,Windows 只有 amd64。 @@ -137,7 +137,7 @@ CPython 来自 python.org。当 python.org 为该架构提供 **EXE** 安装包 2. `python-<版本>.amd64.msi`、`python-<版本>.arm64.msi`,32 位则是 `python-<版本>.msi`, 仅在第 1 步没找到时使用。 -两者都不存在时,安装失败,提示 `No available installer found for current version`。 +两者都不存在时,`vfox install` 会在下载任何文件之前停止,并提示 `Python <版本> has no Windows installer on python.org`。 下面是 python.org 上的两个例子: | 版本 | python.org 上发布的文件 | 使用的安装包 | @@ -147,7 +147,7 @@ CPython 来自 python.org。当 python.org 为该架构提供 **EXE** 安装包 - **EXE:** 这个文件是一个捆绑包。插件用自带的 WiX `dark.exe` 解出其中的 MSI,删除 `launcher.msi`、`path.msi`、`appendpath.msi` 和 `pip.msi`,再用 - `msiexec /quiet /a TargetDir=<目录>` 把其余的 MSI 安装进版本目录,最后运行 + `msiexec /quiet /a TargetDir=<目录>` 把其余的 MSI 安装进 `python-<版本>` 目录,最后运行 `ensurepip`。因为启动器、PATH 和 pip 的 MSI 都被跳过,vfox 的安装不会添加 `py.exe`, 不改动 `PATH`,pip 由 `ensurepip` 提供。 - **MSI:** 插件用同样的方式安装 MSI,即 `msiexec /quiet /a TargetDir=<目录>`, diff --git a/docs/zh-CN/versions.md b/docs/zh-CN/versions.md index 01c6972..6a9c60e 100644 --- a/docs/zh-CN/versions.md +++ b/docs/zh-CN/versions.md @@ -104,7 +104,8 @@ graalpy3.13-community-25.5.5 system ``` -- `3.12` 选已安装的 3.12.x 里最新的。 +- `3.12` 选已安装的 3.12.x 里最新的,和 `vfox use` 一样不会选中自由线程(`t`)或预发布版。 + `3.13t` 选中自由线程版本;预发布版要写完整名字,如 `3.14.0a4`。 - `cpython-3.12.8` 选 `3.12.8`;只装了链接版本时,选 `3.12.8-system`。 - `+freethreaded` 形式选带 `t` 的版本。 - `system` 选最新的 `-system` 链接版本。 @@ -126,9 +127,9 @@ EXE;没有 EXE 时才用 MSI(`python-<版本>.amd64.msi`、`.arm64.msi`,38 检查顺序见 [平台](platforms.md#windows)。 - `.exe` 安装包用插件自带的 WiX `dark.exe` 解开。里面的 MSI 用 - `msiexec /quiet /a` 安装进版本目录;启动器、PATH 和 pip 的 MSI 会被跳过,pip + `msiexec /quiet /a` 安装进 `python-<版本>` 目录;启动器、PATH 和 pip 的 MSI 会被跳过,pip 用 `ensurepip` 装好。 -- 老版本的 `.msi` 安装包用 `msiexec /quiet /a` 安装进版本目录,pip 用 +- 老版本的 `.msi` 安装包用 `msiexec /quiet /a` 安装进 `python-<版本>` 目录,pip 用 `ensurepip` 装好。 - python.org 安装包通常把 `python3.exe`、`python3.12.exe` 之类的别名放在目标 目录外面,插件会在 `python.exe` 旁边补上这些别名。 From 2b47e7656a4e20e8188426fc5c6a79ddec99a4d2 Mon Sep 17 00:00:00 2001 From: Qiheng He Date: Sat, 14 Nov 2026 00:42:24 +0800 Subject: [PATCH 3/4] fix: break ties between installs of one version by name find_installed and newest compared installs by version only. When two installs shared a version, such as 3.12.8-local and 3.12.8-system, the choice depended on the order in which the names were inserted or listed. Lua does not order pairs, so the same names could give different answers. Order equal versions by name after the existing rules: the bare name first, then the name that sorts first. find_release already ends with the same name comparison, so all three paths now agree. Add tests for both insertion orders and for list order, and document the rule in versions, development and the changelog. --- docs/changes.md | 4 ++++ docs/development.md | 4 +++- docs/versions.md | 4 +++- docs/zh-CN/changes.md | 2 ++ docs/zh-CN/development.md | 2 +- docs/zh-CN/versions.md | 2 +- lib/python_version.lua | 14 ++++++++++---- tests/partial_version_test.lua | 12 ++++++++++++ 8 files changed, 36 insertions(+), 8 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index c690e28..1057c0f 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -12,6 +12,10 @@ the rule `vfox use` follows: it no longer selects a free-threaded (`t`) or pre-release install. `3.13t` still selects a free-threaded install; a pre-release needs its full name, such as `3.14.0a4`. +- When two installs share a version, such as `3.12.8-local` and + `3.12.8-system`, `.python-version`, the `latest_installed` fallback and + `system` pick the bare name first, then the name that sorts first. Before, + the choice depended on the order in which the names were listed. ## 0.6.3 diff --git a/docs/development.md b/docs/development.md index 6b1ed90..2f4fb50 100644 --- a/docs/development.md +++ b/docs/development.md @@ -194,7 +194,9 @@ entry falls back to the newest installed name. A partial version such as `3.13` in a `.python-version` file is resolved with `find_release`, the function PreUse uses, so it never selects a free-threaded or pre-release name. Other requests, such as `3.12.8`, are matched as a prefix, -so a linked `3.12.8-system` still counts. +so a linked `3.12.8-system` still counts. When several names share a version, +the bare name wins, then the name that sorts first, so the result does not +depend on the order the names are listed. ### windows_command diff --git a/docs/versions.md b/docs/versions.md index 944996c..51a80c6 100644 --- a/docs/versions.md +++ b/docs/versions.md @@ -118,7 +118,9 @@ system selects a free-threaded (`t`) or pre-release install. `3.13t` selects a free-threaded one; a pre-release needs its full name, such as `3.14.0a4`. - `cpython-3.12.8` selects `3.12.8`, or its linked `3.12.8-system` when only - that is installed. + that is installed. When several installs share the version, the bare name + wins, then the name that sorts first, so `3.12.8-local` is chosen over + `3.12.8-system`; write the full name to choose another. - The `+freethreaded` form selects the `t` version. - `system` selects the newest linked `-system` version. - GraalPy names such as `graalpy-24.2.0` and diff --git a/docs/zh-CN/changes.md b/docs/zh-CN/changes.md index ba09f6b..8220270 100644 --- a/docs/zh-CN/changes.md +++ b/docs/zh-CN/changes.md @@ -8,6 +8,8 @@ `python@3.13t` 会选中自由线程的链接安装,如 `3.13.1t-uv`。来源后缀不再被当作版本的一部分。 - `.python-version` 中的部分版本号(如 `3.13`)与 `vfox use` 遵循同一规则:不再选中自由线程 (`t`)或预发布版。`3.13t` 仍然选中自由线程版本;预发布版请写完整名字,如 `3.14.0a4`。 +- 两个安装的版本号相同(如 `3.12.8-local` 和 `3.12.8-system`)时,`.python-version`、`system` + 和 `latest_installed` 的回退都先选裸版本,其余按名字排序取第一个,不再取决于名字的列出顺序。 ## 0.6.3 diff --git a/docs/zh-CN/development.md b/docs/zh-CN/development.md index c57bd0c..43d1a22 100644 --- a/docs/zh-CN/development.md +++ b/docs/zh-CN/development.md @@ -164,7 +164,7 @@ Windows 上钩子直接返回,上面的检查都不运行。Unix 上,安装 部分版本号(如 `3.13`)在 `.python-version` 里用 `find_release` 解析,和 PreUse 用的是同一个函数, 所以不会选中自由线程或预发布版。其他请求(如 `3.12.8`)按前缀匹配,链接进来的 `3.12.8-system` -仍然算数。 +仍然算数。几个名字版本号相同时,先选裸名字,其余按名字排序取第一个,结果与列出的顺序无关。 ### windows_command diff --git a/docs/zh-CN/versions.md b/docs/zh-CN/versions.md index 6a9c60e..866e18c 100644 --- a/docs/zh-CN/versions.md +++ b/docs/zh-CN/versions.md @@ -106,7 +106,7 @@ system - `3.12` 选已安装的 3.12.x 里最新的,和 `vfox use` 一样不会选中自由线程(`t`)或预发布版。 `3.13t` 选中自由线程版本;预发布版要写完整名字,如 `3.14.0a4`。 -- `cpython-3.12.8` 选 `3.12.8`;只装了链接版本时,选 `3.12.8-system`。 +- `cpython-3.12.8` 选 `3.12.8`;只装了链接版本时,选 `3.12.8-system`。几个安装的版本号相同时,先选裸版本,其余按名字排序取第一个,所以 `3.12.8-local` 排在 `3.12.8-system` 前面;要选哪一个,就写完整名字。 - `+freethreaded` 形式选带 `t` 的版本。 - `system` 选最新的 `-system` 链接版本。 - `graalpy-24.2.0`、`graalpy3.13-community-25.5.5` 这样的 GraalPy 版本名会选中 diff --git a/lib/python_version.lua b/lib/python_version.lua index 90e2f7e..0aba9f7 100644 --- a/lib/python_version.lua +++ b/lib/python_version.lua @@ -45,11 +45,14 @@ function python_version.compare(left, right) return 0 end ---- Returns the newest name in a list, or nil for an empty list. +--- Returns the newest name in a list, or nil for an empty list. Names of the +--- same version are ordered by name, so a bare version comes before a suffixed +--- one, and the result does not depend on the order of the list. function python_version.newest(names) local best for _, name in ipairs(names) do - if not best or python_version.compare(name, best) > 0 then + local order = best and python_version.compare(name, best) or 1 + if not best or order > 0 or order == 0 and name < best then best = name end end @@ -122,7 +125,8 @@ end --- matched as a prefix, so an exact version such as "3.12.8" still selects a --- linked "3.12.8-system". A request of "system" takes the newest linked system --- Python. When two names share a version, a bare install comes before a ---- source-suffixed one, as vfox's own matching does. +--- source-suffixed one. Otherwise the name that sorts first wins, so the result +--- does not depend on the order the names are listed. function python_version.find_installed(installed, request) if type(request) ~= "string" or request == "" then return nil @@ -160,7 +164,9 @@ function python_version.find_installed(installed, request) end if rank then local order = best and python_version.compare(name, best) or 1 - if not best or order > 0 or order == 0 and rank > best_rank then + local ahead = order > 0 or order == 0 and rank > best_rank + local tied = order == 0 and rank == best_rank and name < best + if not best or ahead or tied then best, best_rank = name, rank end end diff --git a/tests/partial_version_test.lua b/tests/partial_version_test.lua index cd406d3..7a3cdae 100644 --- a/tests/partial_version_test.lua +++ b/tests/partial_version_test.lua @@ -106,6 +106,18 @@ assert(python_version.find_installed(set({ "3.14.0a4" }), "3.14.0a4") == "3.14.0 assert(python_version.find_installed(set({ "3.12.8-opt" }), "3.12") == "3.12.8-opt") assert(python_version.find_installed(set({ "3.12.8-system" }), "3.12.8") == "3.12.8-system") +-- Installs of one version: the bare name first, then the name that sorts first. +-- The result must not depend on the order in which the names are given. +assert(python_version.find_installed(set({ "3.12.8-system", "3.12.8-local" }), "3.12.8") == "3.12.8-local") +assert(python_version.find_installed(set({ "3.12.8-local", "3.12.8-system" }), "3.12.8") == "3.12.8-local") +assert(python_version.find_installed(set({ "3.13.1t-system", "3.13.1-system" }), "system") == "3.13.1-system") +assert(python_version.find_installed(set({ "3.13.1-system", "3.13.1t-system" }), "system") == "3.13.1-system") +assert(python_version.newest({ "3.12.8-system", "3.12.8-local" }) == "3.12.8-local") +assert(python_version.newest({ "3.12.8-local", "3.12.8-system" }) == "3.12.8-local") +assert(python_version.newest({ "3.12.8-local", "3.12.8" }) == "3.12.8") +assert(python_version.newest({ "3.12.8", "3.12.8-local" }) == "3.12.8") +assert(python_version.find_release(set({ "3.12.8-system", "3.12.8-local" }), "3.12") == "3.12.8-local") + -- PreInstall: a partial request reads the version list, an exact one does not. local before = reads local package = plugin:PreInstall({ version = "3.12" }) From f9d971f49dcfcf700fa06e740c7b1c1eef86ffbc Mon Sep 17 00:00:00 2001 From: Qiheng He Date: Sat, 14 Nov 2026 00:48:02 +0800 Subject: [PATCH 4/4] fix: pick regular CPython for system and the latest_installed fallback system and the latest_installed fallback compared release numbers across all installed names. A free-threaded or pre-release install could therefore win on its number alone, and GraalPy's release numbers, which are not CPython's, beat CPython versions: system picked graalpy-24.2.0-system over 3.12.3-system. Both now consider only regular CPython installs: a name that starts with its release number and is neither free-threaded nor a pre-release. The fallback uses any installed name only when no CPython install exists, so a machine with only GraalPy still gets one. Free-threaded, pre-release and GraalPy installs are still selected by their full names. --- docs/changes.md | 6 ++++++ docs/development.md | 3 ++- docs/versions.md | 7 +++++-- docs/zh-CN/changes.md | 3 +++ docs/zh-CN/development.md | 2 +- docs/zh-CN/versions.md | 5 +++-- hooks/parse_legacy_file.lua | 4 ++-- lib/python_version.lua | 30 +++++++++++++++++++++++++++--- tests/parse_legacy_file_test.lua | 5 +++++ tests/partial_version_test.lua | 17 +++++++++++++++++ 10 files changed, 71 insertions(+), 11 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index 1057c0f..6557086 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -16,6 +16,12 @@ `3.12.8-system`, `.python-version`, the `latest_installed` fallback and `system` pick the bare name first, then the name that sorts first. Before, the choice depended on the order in which the names were listed. +- `system` and the `latest_installed` fallback now choose a regular CPython + install. Before, they compared release numbers across every installed name, + so `system` picked `graalpy-24.2.0-system` over `3.12.3-system`, and a + free-threaded or pre-release install could win on its number alone. Both + still fall back to any installed name when no CPython install exists. Name a + free-threaded, pre-release or GraalPy install in full to select it. ## 0.6.3 diff --git a/docs/development.md b/docs/development.md index 2f4fb50..df17bd9 100644 --- a/docs/development.md +++ b/docs/development.md @@ -189,7 +189,8 @@ fails silently. The hook returns `{ version = name }` or `{}`. A version that is not installed selects nothing. With `strategy = "latest_installed"`, an unreadable or missing -entry falls back to the newest installed name. +entry falls back to the newest regular CPython install, or else to the newest +installed name. A partial version such as `3.13` in a `.python-version` file is resolved with `find_release`, the function PreUse uses, so it never selects a free-threaded diff --git a/docs/versions.md b/docs/versions.md index 51a80c6..d845e28 100644 --- a/docs/versions.md +++ b/docs/versions.md @@ -122,7 +122,9 @@ system wins, then the name that sorts first, so `3.12.8-local` is chosen over `3.12.8-system`; write the full name to choose another. - The `+freethreaded` form selects the `t` version. -- `system` selects the newest linked `-system` version. +- `system` selects the newest linked `-system` CPython install that is a + regular build. A free-threaded or pre-release install needs its full name, + such as `3.13.1t-system`; GraalPy is selected by its full name too. - GraalPy names such as `graalpy-24.2.0` and `graalpy3.13-community-25.5.5` select the matching installed GraalPy. - PyPy and other implementations are not handled; neither is a path or a @@ -132,7 +134,8 @@ system The file is read for the `specified` strategy. With `legacyVersionFile.strategy: latest_installed` in vfox's configuration, a -missing or unreadable entry falls back to the newest installed Python. +missing or unreadable entry falls back to the newest regular CPython install, or +to the newest installed name when there is none. ## Windows installers diff --git a/docs/zh-CN/changes.md b/docs/zh-CN/changes.md index 8220270..7259d3f 100644 --- a/docs/zh-CN/changes.md +++ b/docs/zh-CN/changes.md @@ -10,6 +10,9 @@ (`t`)或预发布版。`3.13t` 仍然选中自由线程版本;预发布版请写完整名字,如 `3.14.0a4`。 - 两个安装的版本号相同(如 `3.12.8-local` 和 `3.12.8-system`)时,`.python-version`、`system` 和 `latest_installed` 的回退都先选裸版本,其余按名字排序取第一个,不再取决于名字的列出顺序。 +- `system` 和 `latest_installed` 的回退现在只选常规的 CPython 安装。过去它们把所有已安装名字的版本号放在一起比较, + 所以 `system` 会选中 `graalpy-24.2.0-system` 而不是 `3.12.3-system`,自由线程和预发布版也可能仅凭版本号更大而被选中。 + 没有 CPython 安装时,回退仍然选已安装的任意名字。要选中自由线程、预发布版或 GraalPy,请写完整名字。 ## 0.6.3 diff --git a/docs/zh-CN/development.md b/docs/zh-CN/development.md index 43d1a22..5467015 100644 --- a/docs/zh-CN/development.md +++ b/docs/zh-CN/development.md @@ -160,7 +160,7 @@ Windows 上钩子直接返回,上面的检查都不运行。Unix 上,安装 `func() []string`;`ctx:getInstalledVersions()` 会多传一个参数并静默失败。 钩子返回 `{ version = name }` 或 `{}`。没安装的版本不选任何东西。 -`strategy = "latest_installed"` 时,条目缺失或读不懂就退回到已安装的最新名字。 +`strategy = "latest_installed"` 时,条目缺失或读不懂就退回到最新的常规 CPython;没有 CPython 时,退回到已安装的最新名字。 部分版本号(如 `3.13`)在 `.python-version` 里用 `find_release` 解析,和 PreUse 用的是同一个函数, 所以不会选中自由线程或预发布版。其他请求(如 `3.12.8`)按前缀匹配,链接进来的 `3.12.8-system` diff --git a/docs/zh-CN/versions.md b/docs/zh-CN/versions.md index 866e18c..07b2438 100644 --- a/docs/zh-CN/versions.md +++ b/docs/zh-CN/versions.md @@ -108,7 +108,8 @@ system `3.13t` 选中自由线程版本;预发布版要写完整名字,如 `3.14.0a4`。 - `cpython-3.12.8` 选 `3.12.8`;只装了链接版本时,选 `3.12.8-system`。几个安装的版本号相同时,先选裸版本,其余按名字排序取第一个,所以 `3.12.8-local` 排在 `3.12.8-system` 前面;要选哪一个,就写完整名字。 - `+freethreaded` 形式选带 `t` 的版本。 -- `system` 选最新的 `-system` 链接版本。 +- `system` 选最新的 `-system` 链接版本,但只限常规的 CPython 版本。自由线程和预发布版要写完整名字, + 如 `3.13.1t-system`;GraalPy 也要写完整名字。 - `graalpy-24.2.0`、`graalpy3.13-community-25.5.5` 这样的 GraalPy 版本名会选中 对应的已安装 GraalPy。 - 不处理 PyPy 等其他实现,也不处理路径或 `3.12.3/envs/...` 这样的条目。 @@ -116,7 +117,7 @@ system 文件按 `specified` 策略读取。如果 vfox 配置里的 `legacyVersionFile.strategy` 是 `latest_installed`,条目缺失或读不懂时就退回到 -已安装的最新 Python。 +最新的常规 CPython;没有 CPython 时,退回到已安装的最新名字。 ## Windows 安装包 diff --git a/hooks/parse_legacy_file.lua b/hooks/parse_legacy_file.lua index b16028b..c9f275d 100644 --- a/hooks/parse_legacy_file.lua +++ b/hooks/parse_legacy_file.lua @@ -42,7 +42,7 @@ end --- --- 3.12 -> the newest installed 3.12.x --- cpython-3.12.8 -> 3.12.8, or its linked 3.12.8-system ---- system -> the newest linked system Python +--- system -> the newest regular linked system Python --- --- A version that is not installed selects nothing; vfox leaves the current --- version in place rather than installing one behind the user's back. @@ -61,7 +61,7 @@ function PLUGIN:ParseLegacyFile(ctx) local name = python_version.find_installed(installed, request) if name == nil and ctx.strategy == "latest_installed" then - name = python_version.newest(names) + name = python_version.newest_installed(names) end if name == nil then return {} diff --git a/lib/python_version.lua b/lib/python_version.lua index 0aba9f7..4d3b60f 100644 --- a/lib/python_version.lua +++ b/lib/python_version.lua @@ -123,8 +123,8 @@ end --- line such as "3.13" is resolved as find_release resolves it for vfox use, so --- it never selects a free-threaded or pre-release name. Any other request is --- matched as a prefix, so an exact version such as "3.12.8" still selects a ---- linked "3.12.8-system". A request of "system" takes the newest linked system ---- Python. When two names share a version, a bare install comes before a +--- linked "3.12.8-system". A request of "system" takes the newest regular +--- CPython install with a -system suffix. When two names share a version, a bare install comes before a --- source-suffixed one. Otherwise the name that sorts first wins, so the result --- does not depend on the order the names are listed. function python_version.find_installed(installed, request) @@ -135,7 +135,7 @@ function python_version.find_installed(installed, request) if request == "system" then local systems = {} for name in pairs(installed) do - if name:sub(-7) == "-system" then + if name:sub(-7) == "-system" and python_version.is_plain(name) then systems[#systems + 1] = name end end @@ -212,6 +212,30 @@ local function releaseOf(name) return release, free, release:find("%d%a") ~= nil end +--- Whether a name is a regular CPython install: it starts with its release +--- number, and it is neither free-threaded nor a pre-release. GraalPy has its +--- own release numbers, which cannot be compared with CPython's. +function python_version.is_plain(name) + if type(name) ~= "string" or not name:match("^%d") then + return false + end + local _, free, pre = releaseOf(name) + return not free and not pre +end + +--- Picks the install the latest_installed strategy falls back to: the newest +--- regular CPython install, or else the newest installed name of any kind, so a +--- machine that has only GraalPy still gets one. +function python_version.newest_installed(names) + local plain = {} + for _, name in ipairs(names) do + if python_version.is_plain(name) then + plain[#plain + 1] = name + end + end + return python_version.newest(plain) or python_version.newest(names) +end + --- Whether a name is a bare version rather than one with a source suffix. local function isBare(name) return not name:find("-", 1, true) diff --git a/tests/parse_legacy_file_test.lua b/tests/parse_legacy_file_test.lua index 40d4ebc..bb31f24 100644 --- a/tests/parse_legacy_file_test.lua +++ b/tests/parse_legacy_file_test.lua @@ -65,4 +65,9 @@ assert(result.version == nil or result.version == "", tostring(result.version)) result = parse("python-version-pypy", { "3.10.14" }, "latest_installed") assert(result.version == "3.10.14", tostring(result.version)) +-- latest_installed prefers the newest regular CPython install: GraalPy's release +-- number is not comparable with CPython's, so 24.2.0 must not win over 3.12.3. +result = parse("python-version-pypy", { "graalpy-24.2.0", "3.12.3" }, "latest_installed") +assert(result.version == "3.12.3", tostring(result.version)) + print("PASS: .python-version requests and installed-name matching") diff --git a/tests/partial_version_test.lua b/tests/partial_version_test.lua index 7a3cdae..ecf061f 100644 --- a/tests/partial_version_test.lua +++ b/tests/partial_version_test.lua @@ -118,6 +118,23 @@ assert(python_version.newest({ "3.12.8-local", "3.12.8" }) == "3.12.8") assert(python_version.newest({ "3.12.8", "3.12.8-local" }) == "3.12.8") assert(python_version.find_release(set({ "3.12.8-system", "3.12.8-local" }), "3.12") == "3.12.8-local") +-- "system" is a plain request too: it selects the newest regular CPython install +-- named -system. A free-threaded or pre-release install needs its full name, and +-- GraalPy's release numbers cannot be compared with CPython's. +assert(python_version.find_installed(set({ "3.13.2t-system", "3.13.1-system" }), "system") == "3.13.1-system") +assert(python_version.find_installed(set({ "3.14.0a4-system", "3.13.1-system" }), "system") == "3.13.1-system") +assert(python_version.find_installed(set({ "3.13.2t-system" }), "system") == nil) +assert(python_version.find_installed(set({ "3.13.2t-system" }), "3.13.2t-system") == "3.13.2t-system") +assert(python_version.find_installed(set({ "graalpy-24.2.0-system", "3.12.3-system" }), "system") == "3.12.3-system") +assert(python_version.find_installed(set({ "graalpy-24.2.0-system" }), "system") == nil) + +-- The latest_installed fallback: the newest regular CPython install, or else the +-- newest installed name of any kind. +assert(python_version.newest_installed({ "graalpy-24.2.0", "3.12.3" }) == "3.12.3") +assert(python_version.newest_installed({ "3.13.2t", "3.13.1" }) == "3.13.1") +assert(python_version.newest_installed({ "3.14.0a4", "3.13.1-system" }) == "3.13.1-system") +assert(python_version.newest_installed({ "graalpy-24.2.0" }) == "graalpy-24.2.0") + -- PreInstall: a partial request reads the version list, an exact one does not. local before = reads local package = plugin:PreInstall({ version = "3.12" })