|
24 | 24 |
|
25 | 25 | $ErrorActionPreference = "Stop" |
26 | 26 |
|
| 27 | +$Script:InstallerVersion = "1.1.0" |
| 28 | + |
27 | 29 | function Info([string]$Message) { Write-Host " $Message" -ForegroundColor Cyan } |
28 | 30 | function Success([string]$Message) { Write-Host " OK $Message" -ForegroundColor Green } |
29 | 31 | function Warn([string]$Message) { Write-Host " WARN $Message" -ForegroundColor Yellow } |
@@ -118,6 +120,34 @@ function New-ManagedVenv($PythonInfo) { |
118 | 120 |
|
119 | 121 | $venvPython = Join-Path $VenvPath "Scripts\python.exe" |
120 | 122 | if (-not (Test-Path -LiteralPath $venvPython)) { |
| 123 | + # Microsoft Store / UWP Python redirects writes under %LOCALAPPDATA% into |
| 124 | + # %LOCALAPPDATA%\Packages\PythonSoftwareFoundation.Python.*\LocalCache\Local\<rest>. |
| 125 | + # Try to locate the redirected venv and use that path instead. |
| 126 | + $redirected = $null |
| 127 | + $localAppData = $env:LOCALAPPDATA |
| 128 | + if ($localAppData -and $VenvPath.StartsWith($localAppData, [System.StringComparison]::OrdinalIgnoreCase)) { |
| 129 | + $relative = $VenvPath.Substring($localAppData.Length).TrimStart('\','/') |
| 130 | + $packagesRoot = Join-Path $localAppData "Packages" |
| 131 | + if (Test-Path -LiteralPath $packagesRoot) { |
| 132 | + $candidates = Get-ChildItem -LiteralPath $packagesRoot -Directory -ErrorAction SilentlyContinue | |
| 133 | + Where-Object { $_.Name -like "PythonSoftwareFoundation.Python.*" } |
| 134 | + foreach ($pkg in $candidates) { |
| 135 | + $candidateVenv = Join-Path $pkg.FullName (Join-Path "LocalCache\Local" $relative) |
| 136 | + $candidatePython = Join-Path $candidateVenv "Scripts\python.exe" |
| 137 | + if (Test-Path -LiteralPath $candidatePython) { |
| 138 | + $redirected = @{ Venv = $candidateVenv; Python = $candidatePython; Package = $pkg.Name } |
| 139 | + break |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + if ($redirected) { |
| 145 | + Warn "Microsoft Store Python redirected the venv into $($redirected.Package)." |
| 146 | + Warn "Using redirected venv: $($redirected.Venv)" |
| 147 | + Info "To avoid this, install Python from https://www.python.org/downloads/ or via 'winget install -e --id Python.Python.3.12'." |
| 148 | + $Script:VenvPath = $redirected.Venv |
| 149 | + return $redirected.Python |
| 150 | + } |
121 | 151 | throw "Managed venv is missing python.exe: $venvPython" |
122 | 152 | } |
123 | 153 | return $venvPython |
@@ -296,6 +326,20 @@ function Test-PythonExecutable([string]$FilePath, [string[]]$Arguments) { |
296 | 326 | $major = [int]$Matches[1] |
297 | 327 | $minor = [int]$Matches[2] |
298 | 328 | if ($major -lt 3 -or ($major -eq 3 -and $minor -lt 11)) { return $null } |
| 329 | + |
| 330 | + # Reject Microsoft Store Python distributions. They virtualize writes under |
| 331 | + # %LOCALAPPDATA% into %LOCALAPPDATA%\Packages\PythonSoftwareFoundation.Python.*\LocalCache\Local\, |
| 332 | + # which breaks `python -m venv` against our managed venv path. |
| 333 | + try { |
| 334 | + $sysExe = & $FilePath @Arguments -c "import sys; print(sys.executable)" 2>&1 |
| 335 | + if ($LASTEXITCODE -eq 0) { |
| 336 | + $sysExeText = ($sysExe | Out-String).Trim() |
| 337 | + if ($sysExeText -match "\\WindowsApps\\" -or $sysExeText -match "\\Packages\\PythonSoftwareFoundation\.Python\.") { |
| 338 | + return $null |
| 339 | + } |
| 340 | + } |
| 341 | + } catch { } |
| 342 | + |
299 | 343 | return [pscustomobject]@{ |
300 | 344 | FilePath = $FilePath |
301 | 345 | Arguments = $Arguments |
@@ -394,7 +438,13 @@ function Resolve-Python { |
394 | 438 | } |
395 | 439 |
|
396 | 440 | Write-Host "" |
397 | | -Write-Host "X-Tester MCP installer" -ForegroundColor Magenta |
| 441 | +Write-Host " __ __ _____ _ " -ForegroundColor Magenta |
| 442 | +Write-Host " \ \/ / |_ _|__ ___| |_ ___ _ __ " -ForegroundColor Magenta |
| 443 | +Write-Host " \ /_____| |/ _ \/ __| __/ _ \ '__|" -ForegroundColor Magenta |
| 444 | +Write-Host " / \_____| | __/\__ \ || __/ | " -ForegroundColor Magenta |
| 445 | +Write-Host " /_/\_\ |_|\___||___/\__\___|_| " -ForegroundColor Magenta |
| 446 | +Write-Host "" |
| 447 | +Write-Host " X-Tester MCP installer v$Script:InstallerVersion" -ForegroundColor Magenta |
398 | 448 | Write-Host "" |
399 | 449 |
|
400 | 450 | $pythonInfo = Resolve-Python |
|
0 commit comments