71 lines
2.8 KiB
PowerShell
71 lines
2.8 KiB
PowerShell
param(
|
|
[Parameter(ValueFromRemainingArguments = $true)]
|
|
[string[]]$PipArgs
|
|
)
|
|
|
|
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
|
|
|
# Keep pip artifacts local for easy cleanup on minimal/portable machines.
|
|
$env:PIP_CACHE_DIR = Join-Path $repoRoot ".pip\cache"
|
|
$env:TEMP = Join-Path $repoRoot ".tmp\pip-temp"
|
|
$env:TMP = $env:TEMP
|
|
|
|
New-Item -ItemType Directory -Force -Path $env:PIP_CACHE_DIR | Out-Null
|
|
New-Item -ItemType Directory -Force -Path $env:TEMP | Out-Null
|
|
|
|
# Clear proxy/no-index env vars that commonly break package fetch.
|
|
Remove-Item Env:HTTP_PROXY -ErrorAction SilentlyContinue
|
|
Remove-Item Env:HTTPS_PROXY -ErrorAction SilentlyContinue
|
|
Remove-Item Env:ALL_PROXY -ErrorAction SilentlyContinue
|
|
Remove-Item Env:http_proxy -ErrorAction SilentlyContinue
|
|
Remove-Item Env:https_proxy -ErrorAction SilentlyContinue
|
|
Remove-Item Env:all_proxy -ErrorAction SilentlyContinue
|
|
Remove-Item Env:GIT_HTTP_PROXY -ErrorAction SilentlyContinue
|
|
Remove-Item Env:GIT_HTTPS_PROXY -ErrorAction SilentlyContinue
|
|
Remove-Item Env:PIP_NO_INDEX -ErrorAction SilentlyContinue
|
|
|
|
# Keep behavior deterministic and avoid interactive/network hangs.
|
|
$env:PIP_DISABLE_PIP_VERSION_CHECK = "1"
|
|
$env:PIP_DEFAULT_TIMEOUT = "30"
|
|
$env:PIP_RETRIES = "2"
|
|
|
|
if (-not $PipArgs -or $PipArgs.Count -eq 0) {
|
|
Write-Host "Usage: ./scripts/pip-min.ps1 <pip args>"
|
|
Write-Host "Example: ./scripts/pip-min.ps1 install --index-url https://pypi.org/simple faster-whisper"
|
|
exit 2
|
|
}
|
|
|
|
# Default install target to a repo-local directory so installs do not require
|
|
# user/site-packages write access on constrained hosts.
|
|
$effectiveArgs = @($PipArgs)
|
|
$firstArg = $effectiveArgs[0].ToLowerInvariant()
|
|
if ($firstArg -eq "install") {
|
|
# On Windows, map PyAudio to pyaudiowpatch (wheel available for newer CPython),
|
|
# avoiding source builds that require PortAudio headers/toolchain wiring.
|
|
for ($i = 0; $i -lt $effectiveArgs.Count; $i++) {
|
|
$arg = $effectiveArgs[$i]
|
|
if ($arg -match '^(?i)pyaudio($|[<>=!~].*)') {
|
|
$suffix = $arg.Substring(7)
|
|
$effectiveArgs[$i] = "pyaudiowpatch$suffix"
|
|
Write-Host "pip-min: mapped '$arg' -> '$($effectiveArgs[$i])' on Windows."
|
|
}
|
|
}
|
|
|
|
$hasTarget = $effectiveArgs -contains "--target" -or $effectiveArgs -contains "-t" -or $effectiveArgs -contains "--prefix"
|
|
if (-not $hasTarget) {
|
|
$effectiveArgs = $effectiveArgs | Where-Object { $_ -ne "--user" }
|
|
$localTarget = Join-Path $repoRoot ".pydeps\py314"
|
|
New-Item -ItemType Directory -Force -Path $localTarget | Out-Null
|
|
$effectiveArgs += @("--target", $localTarget)
|
|
Write-Host "pip-min: using local target $localTarget"
|
|
}
|
|
}
|
|
|
|
$pipWrapper = Join-Path $PSScriptRoot "pip_safe.py"
|
|
if (Test-Path $pipWrapper) {
|
|
& python $pipWrapper @effectiveArgs
|
|
} else {
|
|
& python -m pip @effectiveArgs
|
|
}
|
|
exit $LASTEXITCODE
|