Skip to content

Commit faabd7a

Browse files
authored
Update install.ps1
1 parent 8388215 commit faabd7a

1 file changed

Lines changed: 51 additions & 1 deletion

File tree

deepstudio/xtester/install.ps1

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ param(
2424

2525
$ErrorActionPreference = "Stop"
2626

27+
$Script:InstallerVersion = "1.1.0"
28+
2729
function Info([string]$Message) { Write-Host " $Message" -ForegroundColor Cyan }
2830
function Success([string]$Message) { Write-Host " OK $Message" -ForegroundColor Green }
2931
function Warn([string]$Message) { Write-Host " WARN $Message" -ForegroundColor Yellow }
@@ -118,6 +120,34 @@ function New-ManagedVenv($PythonInfo) {
118120

119121
$venvPython = Join-Path $VenvPath "Scripts\python.exe"
120122
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+
}
121151
throw "Managed venv is missing python.exe: $venvPython"
122152
}
123153
return $venvPython
@@ -296,6 +326,20 @@ function Test-PythonExecutable([string]$FilePath, [string[]]$Arguments) {
296326
$major = [int]$Matches[1]
297327
$minor = [int]$Matches[2]
298328
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+
299343
return [pscustomobject]@{
300344
FilePath = $FilePath
301345
Arguments = $Arguments
@@ -394,7 +438,13 @@ function Resolve-Python {
394438
}
395439

396440
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
398448
Write-Host ""
399449

400450
$pythonInfo = Resolve-Python

0 commit comments

Comments
 (0)