68 lines
2.0 KiB
PowerShell
68 lines
2.0 KiB
PowerShell
[CmdletBinding()]
|
||
param(
|
||
[string]$PythonExe = "python",
|
||
[string]$RepoUrl = "https://github.com/opendatalab/MinerU.git",
|
||
[string]$Branch = "main",
|
||
[string]$InstallDir,
|
||
[switch]$ForceClone
|
||
)
|
||
|
||
$ErrorActionPreference = "Stop"
|
||
|
||
if (-not $InstallDir) {
|
||
$InstallDir = Join-Path $PSScriptRoot ".venv"
|
||
}
|
||
|
||
function Test-Command {
|
||
param([string]$Name)
|
||
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
|
||
throw "找不到命令 $Name,请先安装。"
|
||
}
|
||
}
|
||
|
||
Test-Command -Name $PythonExe
|
||
Test-Command -Name git
|
||
|
||
Write-Host ">>> 使用 $PythonExe 创建/更新虚拟环境:$InstallDir"
|
||
if (-not (Test-Path $InstallDir) -or $ForceClone) {
|
||
& $PythonExe -m venv $InstallDir | Out-Null
|
||
}
|
||
$venvPython = Join-Path $InstallDir "Scripts/python.exe"
|
||
if (-not (Test-Path $venvPython)) {
|
||
throw "未找到虚拟环境 Python:$venvPython"
|
||
}
|
||
|
||
Write-Host ">>> 安装 pip 依赖"
|
||
& $venvPython -m pip install -U pip setuptools wheel | Out-Null
|
||
$extraReq = Join-Path $PSScriptRoot "requirements.txt"
|
||
if (Test-Path $extraReq) {
|
||
& $venvPython -m pip install -r $extraReq
|
||
}
|
||
|
||
$srcDir = Join-Path $PSScriptRoot "src"
|
||
if (-not (Test-Path $srcDir) -or $ForceClone) {
|
||
if (Test-Path $srcDir) {
|
||
Remove-Item -Recurse -Force $srcDir
|
||
}
|
||
Write-Host ">>> Clone MinerU 仓库:$RepoUrl -> $srcDir"
|
||
git clone --branch $Branch $RepoUrl $srcDir | Out-Null
|
||
} else {
|
||
Write-Host ">>> 更新 $srcDir"
|
||
git -C $srcDir fetch --all --prune | Out-Null
|
||
git -C $srcDir checkout $Branch | Out-Null
|
||
git -C $srcDir pull | Out-Null
|
||
}
|
||
|
||
$requirementFile = Join-Path $srcDir "requirements.txt"
|
||
if (Test-Path $requirementFile) {
|
||
Write-Host ">>> 安装 MinerU 官方依赖"
|
||
& $venvPython -m pip install -r $requirementFile
|
||
} else {
|
||
Write-Warning "未找到 $requirementFile,请参照官方 README 手动安装依赖。"
|
||
}
|
||
|
||
Write-Host ">>> 准备完成"
|
||
Write-Host "虚拟环境:$InstallDir"
|
||
Write-Host "仓库路径:$srcDir"
|
||
Write-Host "可执行 ./start.ps1 -Host 127.0.0.1 -Port 18888 启动 MinerU 服务。"
|