From 86751ccab56c3496c240eeae0db93c732d792853 Mon Sep 17 00:00:00 2001 From: artin Date: Sat, 25 Jan 2025 17:24:32 +0800 Subject: [PATCH 1/2] feat: get versions from pyenv --- hooks/available.lua | 6 ++++- hooks/pre_install.lua | 4 ++- lib/util.lua | 62 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/hooks/available.lua b/hooks/available.lua index f00d37a..2d8f2b2 100644 --- a/hooks/available.lua +++ b/hooks/available.lua @@ -1,4 +1,8 @@ require("util") function PLUGIN:Available(ctx) - return parseVersion() + if OS_TYPE == "windows" then + return parseVersion() + else + return parseVersionFromPyenv() + end end \ No newline at end of file diff --git a/hooks/pre_install.lua b/hooks/pre_install.lua index 7069583..c08dd30 100644 --- a/hooks/pre_install.lua +++ b/hooks/pre_install.lua @@ -1,10 +1,12 @@ require("util") function PLUGIN:PreInstall(ctx) local version = ctx.version + if version == "latest" then version = self:Available({})[1].version end - if not checkIsReleaseVersion(version) then + + if OS_TYPE == "windows" and not checkIsReleaseVersion(version) then error("The current version is not released") return end diff --git a/lib/util.lua b/lib/util.lua index 0a414c3..47584bc 100644 --- a/lib/util.lua +++ b/lib/util.lua @@ -1,5 +1,6 @@ local http = require("http") local html = require("html") +local json = require("json") -- get mirror local PYTHON_URL = "https://www.python.org/ftp/python/" @@ -10,6 +11,8 @@ if VFOX_PYTHON_MIRROR then os.setenv("PYTHON_BUILD_MIRROR_URL", PYTHON_URL) end +local version_vault_url = "https://version-vault.cdn.dog/pyenv-versions" + -- request headers local REQUEST_HEADERS = { ["User-Agent"] = "vfox" @@ -231,6 +234,7 @@ function linuxCompile(ctx) error("remove build tool failed") end end + function getReleaseForWindows(version) local archType = RUNTIME.archType if archType == "386" then @@ -259,7 +263,14 @@ function getReleaseForWindows(version) print("url:\t" .. url) error("No available installer found for current version") end + +function fixHeaders() + REQUEST_HEADERS["User-Agent"] = "vfox v" .. RUNTIME.version; +end + function parseVersion() + fixHeaders() + local resp, err = http.get({ url = PYTHON_URL, headers = REQUEST_HEADERS @@ -318,3 +329,54 @@ function compare_versions(v1, v2) return 0 end + +function parseVersionFromPyenv() + fixHeaders() + local resp, err = http.get({ + url = version_vault_url, + headers = REQUEST_HEADERS + }) + if err ~= nil or resp.status_code ~= 200 then + error("paring release info failed." .. err) + end + local result = {} + local jsonObj = json.decode(resp.body) + + local tagName = jsonObj.tagName; + local versions = jsonObj.versions; + + local numericVersions = {} + local namedVersions = {} + + for _, version in ipairs(versions) do + if string.match(version, "^%d") then + table.insert(numericVersions, version) + else + table.insert(namedVersions, version) + end + end + + table.sort(numericVersions, function(a, b) + return compare_versions(a, b) > 0 + end) + + table.sort(namedVersions, function(a, b) + return compare_versions(a, b) > 0 + end) + + for _, version in ipairs(numericVersions) do + table.insert(result, { + version = version, + note = "" + }) + end + + for _, version in ipairs(namedVersions) do + table.insert(result, { + version = version, + note = "" + }) + end + + return result +end \ No newline at end of file From b47aa8073482dd8739214c0ee3ab197ccc5afdaf Mon Sep 17 00:00:00 2001 From: artin Date: Sat, 25 Jan 2025 17:28:09 +0800 Subject: [PATCH 2/2] docs: update readme --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8b23dc6..b35f993 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # vfox-python -Python plugin for [vfox](https://vfox.lhan.me/). +Python plugin for [vfox](https://vfox.lhan.me/). ## Install @@ -10,7 +10,9 @@ After installing [vfox](https://github.com/version-fox/vfox), install the plugin vfox add python ``` +if you want install the free-threaded mode of python, you can select the version ends with `t`, like `v3.14.0a4t`. + ## Mirror You can configure the mirror by `VFOX_PYTHON_MIRROR` environment variable. The default value -is `https://www.python.org/ftp/python/`. \ No newline at end of file +is `https://www.python.org/ftp/python/`.