$ErrorActionPreference = 'Stop' $root = Split-Path -Parent $MyInvocation.MyCommand.Path Set-Location -LiteralPath $root function Import-DotEnv { param( [Parameter(Mandatory = $true)] [string] $Path ) if (-not (Test-Path -LiteralPath $Path)) { return } foreach ($raw in Get-Content -LiteralPath $Path) { $line = $raw.Trim() if ($line -eq '' -or $line.StartsWith('#')) { continue } $eq = $line.IndexOf('=') if ($eq -lt 1) { continue } $key = $line.Substring(0, $eq).Trim() $value = $line.Substring($eq + 1).Trim() if ($value.Length -ge 2) { $quote = $value[0] if (($quote -eq '"' -or $quote -eq "'") -and $value[-1] -eq $quote) { $value = $value.Substring(1, $value.Length - 2) } } if ($key -eq '' -or $value -eq '') { continue } $current = [Environment]::GetEnvironmentVariable($key, 'Process') if ([string]::IsNullOrWhiteSpace($current)) { Set-Item -Path "Env:$key" -Value $value } } } Import-DotEnv -Path (Join-Path $root '.env') Import-DotEnv -Path (Join-Path (Split-Path -Parent $root) 'rpa_oms\.env') $venvPy = Join-Path $root '.venv\Scripts\python.exe' $pyArgs = @('main.py') + @($args) if (Test-Path -LiteralPath $venvPy) { & $venvPy @pyArgs if ($LASTEXITCODE -ne 0) { throw "选品退出码 $LASTEXITCODE" } return } $uv = Get-Command uv -ErrorAction SilentlyContinue if ($null -eq $uv) { throw "找不到 uv,也没有 选品流程\.venv\Scripts\python.exe" } $uvArgs = @('run', '--python', '3.12', 'python') + $pyArgs & $uv.Source @uvArgs if ($LASTEXITCODE -ne 0) { throw "选品退出码 $LASTEXITCODE" }