diff --git a/bucket/uv.json b/bucket/uv.json index 8ac4a47194642..b716015296035 100644 --- a/bucket/uv.json +++ b/bucket/uv.json @@ -17,11 +17,114 @@ "hash": "e99c56f9ab5e1e1ddcaea3e2389990c94baf38e0d7cb2148de08baf2d3261d49" } }, + "pre_install": [ + "# Migrate legacy UV data if it exists and the new persist directory doesn't exist", + "$legacy_uv = Join-Path -Path $env:APPDATA -ChildPath 'uv'", + "if ((Test-Path $legacy_uv) -and -not (Test-Path $persist_dir)) {", + " Write-Host \"Migrating legacy uv data from '$legacy_uv' to '$persist_dir'.\" -ForegroundColor Yellow", + " # --- Legacy locations ---", + " $legacy_uv_python_data = Join-Path -Path $legacy_uv -ChildPath 'python'", + " $legacy_uv_python_shims = Join-Path (Join-Path $env:USERPROFILE '.local') 'bin'", + " $legacy_uv_tools = Join-Path -Path $legacy_uv -ChildPath 'tools'", + " $legacy_uv_tools_shims = Join-Path (Join-Path $env:USERPROFILE '.local') 'bin'", + " # --- Persist target layout ---", + " $persist_python_root = Join-Path $persist_dir 'python'", + " $persist_python_versions = Join-Path $persist_python_root 'versions'", + " $persist_python_shims = Join-Path $persist_python_root 'shims'", + " $persist_tools_root = Join-Path $persist_dir 'tools'", + " $persist_tools_versions = Join-Path $persist_tools_root 'versions'", + " $persist_tools_shims = Join-Path $persist_tools_root 'shims'", + " # Create target directories", + " $null = New-Item -ItemType Directory -Force -Path @(", + " $persist_dir,", + " $persist_python_root, $persist_python_versions, $persist_python_shims,", + " $persist_tools_root, $persist_tools_versions, $persist_tools_shims", + " )", + " # ---- Move Python \"versions\" content ----", + " if (Test-Path $legacy_uv_python_data) {", + " Write-Host \"-> Moving Python versions from '$legacy_uv_python_data' to '$persist_python_versions'...\" -ForegroundColor Cyan", + " Get-ChildItem -Path $legacy_uv_python_data -Force | ForEach-Object {", + " Move-Item -LiteralPath $_.FullName -Destination $persist_python_versions -Force -ErrorAction Stop", + " }", + " } else {", + " Write-Host \"-> No legacy Python versions found at '$legacy_uv_python_data'.\" -ForegroundColor DarkGray", + " }", + " # ---- Move Python shims: only python.exe or python..exe ----", + " if (Test-Path $legacy_uv_python_shims) {", + " $pythonShimRegex = '^(python(\\d+\\.\\d+)?)\\.exe$'", + " $pythonShims = Get-ChildItem -Path $legacy_uv_python_shims -File -Force | Where-Object { $_.Name -match $pythonShimRegex }", + " if ($pythonShims) {", + " Write-Host \"-> Moving Python shims to '$persist_python_shims': $($pythonShims.Name -join ', ')\" -ForegroundColor Cyan", + " foreach ($shim in $pythonShims) {", + " Move-Item -LiteralPath $shim.FullName -Destination (Join-Path $persist_python_shims $shim.Name) -Force -ErrorAction Stop", + " }", + " } else {", + " Write-Host \"-> No valid Python shims found in '$legacy_uv_python_shims'.\" -ForegroundColor DarkGray", + " }", + " } else {", + " Write-Host \"-> Legacy Python shim directory not found at '$legacy_uv_python_shims'.\" -ForegroundColor DarkGray", + " }", + " # ---- Move Tools \"versions\" content ----", + " if (Test-Path $legacy_uv_tools) {", + " Write-Host \"-> Moving Tools versions from '$legacy_uv_tools' to '$persist_tools_versions'...\" -ForegroundColor Cyan", + " Get-ChildItem -Path $legacy_uv_tools -Force | ForEach-Object {", + " Move-Item -LiteralPath $_.FullName -Destination $persist_tools_versions -Force -ErrorAction Stop", + " }", + " } else {", + " Write-Host \"-> No legacy Tools found at '$legacy_uv_tools'.\" -ForegroundColor DarkGray", + " }", + " # ---- Move Tools shims: only those matching folder names under /tools/versions ----", + " $toolNames = @()", + " if (Test-Path $persist_tools_versions) {", + " $toolNames = Get-ChildItem -Path $persist_tools_versions -Directory -Force | Select-Object -ExpandProperty Name", + " }", + " if ($toolNames.Count -gt 0 -and (Test-Path $legacy_uv_tools_shims)) {", + " # For each tool name, move \".exe\" if present", + " $moved = @()", + " foreach ($tool in $toolNames) {", + " $candidate = Join-Path $legacy_uv_tools_shims ($tool + '.exe')", + " if (Test-Path $candidate) {", + " Move-Item -LiteralPath $candidate -Destination (Join-Path $persist_tools_shims ($tool + '.exe')) -Force -ErrorAction Stop", + " $moved += ($tool + '.exe')", + " }", + " }", + " if ($moved.Count -gt 0) {", + " Write-Host \"-> Moved tool shims to '$persist_tools_shims': $($moved -join ', ')\" -ForegroundColor Cyan", + " } else {", + " Write-Host \"-> No matching tool shims found in '$legacy_uv_tools_shims' for tools: $($toolNames -join ', ').\" -ForegroundColor DarkGray", + " }", + " } else {", + " if (-not (Test-Path $legacy_uv_tools_shims)) {", + " Write-Host \"-> Legacy tools shim directory not found at '$legacy_uv_tools_shims'.\" -ForegroundColor DarkGray", + " } else {", + " Write-Host \"-> No tool folders found under '$persist_tools_versions'; skipping shim migration.\" -ForegroundColor DarkGray", + " }", + " }", + "} elseif ((Test-Path $legacy_uv) -and (Test-Path $persist_dir)) {", + " Write-Host \"Found both '$legacy_uv' and '$persist_dir'. Skipping auto-migration; please migrate manually if needed.\" -ForegroundColor Yellow", + "}" + ], "bin": [ "uv.exe", "uvx.exe", "uvw.exe" ], + "env_add_path": [ + "python\\shims", + "tools\\shims" + ], + "env_set": { + "UV_PYTHON_BIN_DIR": "$dir\\python\\shims", + "UV_PYTHON_INSTALL_DIR": "$dir\\python\\versions", + "UV_TOOL_BIN_DIR": "$dir\\tools\\shims", + "UV_TOOL_DIR": "$dir\\tools\\versions" + }, + "persist": [ + "python\\versions", + "python\\shims", + "tools\\versions", + "tools\\shims" + ], "checkver": { "github": "https://github.com/astral-sh/uv" },