35 lines
1.2 KiB
PowerShell
35 lines
1.2 KiB
PowerShell
[CmdletBinding()]
|
||
param(
|
||
[string]$ListenHost,
|
||
[int]$ListenPort,
|
||
[string]$ModulePath
|
||
)
|
||
|
||
$ErrorActionPreference = "Stop"
|
||
|
||
$resolvedHost = if ($PSBoundParameters.ContainsKey("ListenHost")) { $ListenHost } elseif ($env:MINERU_HOST) { $env:MINERU_HOST } else { "127.0.0.1" }
|
||
$resolvedPort = if ($PSBoundParameters.ContainsKey("ListenPort")) { $ListenPort } elseif ($env:MINERU_PORT) { [int]$env:MINERU_PORT } else { 18888 }
|
||
$resolvedModule = if ($PSBoundParameters.ContainsKey("ModulePath")) { $ModulePath } elseif ($env:MINERU_MODULE) { $env:MINERU_MODULE } else { "mineru.cli.fast_api:app" }
|
||
|
||
$venvDir = Join-Path $PSScriptRoot ".venv"
|
||
$pythonBin = Join-Path $venvDir "Scripts" "python.exe"
|
||
if (-not (Test-Path $pythonBin)) {
|
||
throw "未找到虚拟环境 Python:$pythonBin,请先执行 setup.ps1"
|
||
}
|
||
|
||
$srcDir = Join-Path $PSScriptRoot "src"
|
||
if (-not (Test-Path $srcDir)) {
|
||
throw "未找到 MinerU 源码:$srcDir,请先执行 setup.ps1"
|
||
}
|
||
|
||
Push-Location $srcDir
|
||
try {
|
||
$env:PYTHONPATH = $srcDir
|
||
$cmd = "$pythonBin -m uvicorn $resolvedModule --host $resolvedHost --port $resolvedPort"
|
||
Write-Host ">>> 启动 MinerU:$cmd"
|
||
& $pythonBin -m uvicorn $resolvedModule --host $resolvedHost --port $resolvedPort
|
||
}
|
||
finally {
|
||
Pop-Location
|
||
}
|