Skip to content

Commit fbff447

Browse files
Copilotbytemain
andauthored
Use vfox archiver for uv-build extraction
Agent-Logs-Url: https://github.com/version-fox/vfox-python/sessions/7cdb501a-83df-4069-a550-265c36cc0e0e Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com>
1 parent 2ac5b8c commit fbff447

1 file changed

Lines changed: 41 additions & 8 deletions

File tree

lib/util.lua

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,27 @@ local function uvBuildAssetName(build)
415415
return ""
416416
end
417417

418+
local function isSupportedArchiveName(name)
419+
return string.sub(name, -7) == ".tar.gz" or
420+
string.sub(name, -4) == ".tgz" or
421+
string.sub(name, -7) == ".tar.xz" or
422+
string.sub(name, -8) == ".tar.bz2" or
423+
string.sub(name, -4) == ".zip" or
424+
string.sub(name, -3) == ".7z"
425+
end
426+
418427
local function uvBuildAssetPriority(build)
419428
local name = uvBuildAssetName(build)
420-
if string.find(name, "pgo+lto-full", 1, true) or string.find(name, "pgo%2blto-full", 1, true) then
421-
return 10
429+
if not isSupportedArchiveName(name) then
430+
return 90
422431
end
423432
if string.find(name, "install_only_stripped", 1, true) then
424-
return 20
433+
return 10
425434
end
426435
if string.find(name, "install_only", 1, true) then
436+
return 20
437+
end
438+
if string.find(name, "pgo+lto-full", 1, true) or string.find(name, "pgo%2blto-full", 1, true) then
427439
return 30
428440
end
429441
if not string.find(name, "debug", 1, true) then
@@ -493,6 +505,30 @@ local function uvBuildDownloadUrl(build)
493505
return trimTrailingSlash(mirror) .. "/" .. release .. "/" .. filename
494506
end
495507

508+
local function uvBuildArchivePath(path, build)
509+
local filename = build.filename
510+
if filename == nil or filename == "" then
511+
filename = string.match(build.url, "[^/]+$")
512+
end
513+
if filename == nil or filename == "" or string.find(filename, "[/\\\r\n%z]") then
514+
error("Invalid uv-build archive filename")
515+
end
516+
return path .. "/" .. filename
517+
end
518+
519+
local function extractUvBuildArchive(archivePath, path)
520+
local filename = string.lower(archivePath)
521+
if not isSupportedArchiveName(filename) then
522+
error("Unsupported uv-build archive format: " .. archivePath)
523+
end
524+
525+
local archiver = require("vfox.archiver")
526+
local err = archiver.decompress(archivePath, path)
527+
if err ~= nil then
528+
error("Failed to extract uv-build archive: " .. err)
529+
end
530+
end
531+
496532
local function getUvBuilds(osType, archType, libc)
497533
fixHeaders()
498534
local resp, err = http.get({
@@ -588,7 +624,7 @@ function uvBuildInstall(ctx)
588624
local version = sdkInfo.version
589625
local build = findUvBuild(version)
590626
local downloadUrl = uvBuildDownloadUrl(build)
591-
local archivePath = path .. "/python-uv-build.tar"
627+
local archivePath = uvBuildArchivePath(path, build)
592628

593629
if not ctx.rootPath or ctx.rootPath == "" then
594630
error("vfox root path is required for uv-build installation")
@@ -611,10 +647,7 @@ function uvBuildInstall(ctx)
611647
verifyUvBuildArchive(archivePath, uvBuildSha256(build))
612648

613649
print("Extracting Python uv-build archive...")
614-
local status = os.execute("tar -xf " .. shellQuote(archivePath) .. " --strip-components=1 -C " .. shellQuote(path))
615-
if status ~= 0 then
616-
error("Failed to extract uv-build archive. Status: " .. status .. ". Ensure tar is available, the archive is valid, and disk permissions/space are sufficient")
617-
end
650+
extractUvBuildArchive(archivePath, path)
618651
os.remove(archivePath)
619652

620653
local extractedPath = resolvePythonInstallPath(path, version)

0 commit comments

Comments
 (0)