chore: 环境包依赖收敛到 requirements.txt,清理旧插件目录与 _pack.py
- build-python-env.ps1:白名单只留包名,版本统一从仓库根 requirements.txt 解析;-FromVenv 打包前加版本守卫校验 .venv 一致性,支持 -ShowDeps 只打印解析结果 - 桌面端发版SOP 同步新流程与历史坑(1.1.9 环境包、禁止用 -FromVenv 打补丁包) - requirements.txt 补 pycryptodome 3.24.0;package-lock 版本对齐 1.10.8 - 删除已废弃的插件级 _pack.py(统一走 tools/agent_cli.py 打包)与旧英文目录 plugins/xq0077(已由 XQ0077 携程数据导出 取代)
This commit is contained in:
@@ -21,7 +21,8 @@ param(
|
||||
[string]$EnvVersion = "1.0.0",
|
||||
[switch]$FromVenv, # 从本地 .venv 全量打包(推荐,不联网)
|
||||
[switch]$SkipLocal, # do NOT install into electron-shell/python-env/
|
||||
[switch]$Force # re-download embeddable / get-pip
|
||||
[switch]$Force, # re-download embeddable / get-pip
|
||||
[switch]$ShowDeps # 只解析并打印依赖清单后退出(校验 requirements.txt 用,不打包)
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -39,27 +40,85 @@ $EmbedZip = Join-Path $DownloadDir "python-$PythonVersion-embed-amd64.zip"
|
||||
$GetPip = Join-Path $DownloadDir "get-pip.py"
|
||||
$PipIndex = $null # e.g. "https://pypi.tuna.tsinghua.edu.cn/simple"
|
||||
|
||||
# All dependencies (top-level + key transitive), pinned to .venv-validated versions
|
||||
$Pinned = @(
|
||||
"requests==2.34.2", "python-dotenv==1.2.2", "cryptography==50.0.1", "pycryptodome==3.24.0",
|
||||
"pandas==3.0.5", "numpy==2.3.5", "openpyxl==3.1.5",
|
||||
"python-dateutil==2.9.0.post0", "tzdata==2026.3", "et-xmlfile",
|
||||
"websocket-client==1.9.0",
|
||||
"DrissionPage==4.1.1.4", "DrissionGet==1.2.1", "DrissionRecord==2.0.1",
|
||||
"lxml==6.1.1", "psutil==7.2.2", "tldextract==5.3.2", "cssselect==1.5.0", "click==8.4.2",
|
||||
"ddddocr==1.6.1", "onnxruntime==1.28.0", "Pillow==12.3.0",
|
||||
"opencv-python-headless==5.0.0.93", "flatbuffers==25.12.19", "protobuf==7.35.1",
|
||||
# ================== 依赖清单:版本唯一真源 = 仓库根 requirements.txt ==================
|
||||
# 历史坑:这里曾硬编码一份 pin 列表(第三份清单),与 requirements.txt 长期漂移
|
||||
# (numpy/pandas/onnxruntime 等都落后多个小版本),而 .venv 装的是 requirements 的版本,
|
||||
# 导致「-FromVenv 打包」与「embeddable+pip 打包」产物不一致。
|
||||
# 现在只维护「环境包需要哪些包」的白名单,版本一律从 requirements.txt 解析。
|
||||
$ReqFile = Join-Path $Repo "requirements.txt"
|
||||
if (-not (Test-Path $ReqFile)) { throw "缺少依赖清单:$ReqFile" }
|
||||
$ReqVersion = @{}
|
||||
foreach ($line in Get-Content -Path $ReqFile) {
|
||||
if ($line -match '^\s*([A-Za-z0-9][A-Za-z0-9_.\-]*)\s*==\s*([^\s;#]+)') {
|
||||
$ReqVersion[$matches[1].ToLower().Replace('_', '-').Replace('.', '-')] = $matches[2]
|
||||
}
|
||||
}
|
||||
|
||||
# 环境包白名单(只写包名,版本取自 requirements.txt)
|
||||
$EnvPackages = @(
|
||||
"requests", "python-dotenv", "cryptography", "pycryptodome",
|
||||
"pandas", "numpy", "openpyxl",
|
||||
"python-dateutil", "tzdata", "et-xmlfile",
|
||||
"websocket-client",
|
||||
"DrissionPage", "DrissionGet", "DrissionRecord",
|
||||
"lxml", "psutil", "tldextract", "cssselect", "click",
|
||||
"ddddocr", "onnxruntime", "Pillow",
|
||||
"opencv-python-headless", "flatbuffers", "protobuf",
|
||||
# OCR(XQ0003 请假附件:病假/结婚证/产检关键词与登记日期核验)
|
||||
# rapidocr>=3 必须显式固定,连同 opencv_python/omegaconf 等运行依赖,否则
|
||||
# 走 embeddable+pip 模式时该栈不会装、插件 OCR 全面降级为人工复核。
|
||||
"rapidocr==3.9.2", "opencv-python==5.0.0.93",
|
||||
"omegaconf==2.3.1", "antlr4-python3-runtime==4.9.3", "colorlog==6.12.0",
|
||||
"pyclipper==1.4.0", "Shapely==2.1.2", "PyYAML==6.0.3", "tqdm==4.70.1",
|
||||
"pywin32==312",
|
||||
"urllib3==2.7.0", "certifi==2026.7.22", "idna==3.18",
|
||||
"charset-normalizer==3.4.9", "six==1.17.0", "packaging==26.3"
|
||||
"rapidocr", "opencv-python",
|
||||
"omegaconf", "antlr4-python3-runtime", "colorlog",
|
||||
"pyclipper", "Shapely", "PyYAML", "tqdm",
|
||||
"pywin32",
|
||||
"urllib3", "certifi", "idna",
|
||||
"charset-normalizer", "six", "packaging"
|
||||
)
|
||||
|
||||
$Pinned = @()
|
||||
foreach ($p in $EnvPackages) {
|
||||
$k = $p.ToLower().Replace('_', '-').Replace('.', '-')
|
||||
if (-not $ReqVersion.ContainsKey($k)) { throw "requirements.txt 缺少环境包依赖:$p" }
|
||||
$Pinned += "$p==$($ReqVersion[$k])"
|
||||
}
|
||||
Write-Host "依赖来源:requirements.txt(白名单 $($Pinned.Count) 个包)" -ForegroundColor DarkGray
|
||||
# 版本守卫:本地 .venv 必须与 requirements.txt 一致(唯一真源),否则打出来的包会跟随
|
||||
# 一个「没被记录」的版本。返回对象(用对象而非数组:PowerShell 里返回空数组会被展开成 $null):
|
||||
# Found = $false 表示 .venv 不存在;否则 Drift 为漂移项数组。
|
||||
function Get-VenvDrift([string]$VenvPath) {
|
||||
$VenvPy = Join-Path $VenvPath "Scripts\python.exe"
|
||||
if (-not (Test-Path $VenvPy)) { return [pscustomobject]@{ Found = $false; Drift = @() } }
|
||||
$Frozen = @{}
|
||||
& $VenvPy -m pip freeze 2>$null | ForEach-Object {
|
||||
if ($_ -match '^([A-Za-z0-9][A-Za-z0-9_.\-]*)\s*==\s*([^\s]+)') {
|
||||
$Frozen[$matches[1].ToLower().Replace('_', '-').Replace('.', '-')] = $matches[2]
|
||||
}
|
||||
}
|
||||
$drift = @()
|
||||
foreach ($p in $EnvPackages) {
|
||||
$k = $p.ToLower().Replace('_', '-').Replace('.', '-')
|
||||
$want = $ReqVersion[$k]
|
||||
$have = $Frozen[$k]
|
||||
if ($have -ne $want) { $drift += "$p .venv=$have / requirements.txt=$want" }
|
||||
}
|
||||
return [pscustomobject]@{ Found = $true; Drift = $drift }
|
||||
}
|
||||
|
||||
if ($ShowDeps) {
|
||||
$Pinned | ForEach-Object { Write-Host " $_" }
|
||||
$guard = Get-VenvDrift (Join-Path $Repo ".venv")
|
||||
if (-not $guard.Found) {
|
||||
Write-Host " (.venv 不存在,跳过版本一致性校验)" -ForegroundColor DarkGray
|
||||
} elseif ($guard.Drift.Count -eq 0) {
|
||||
Write-Host " 版本守卫通过:.venv 与 requirements.txt 一致($($EnvPackages.Count) 个包)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host " [!] 本地 .venv 与 requirements.txt 不一致:" -ForegroundColor Yellow
|
||||
$guard.Drift | ForEach-Object { Write-Host " $_" -ForegroundColor Yellow }
|
||||
}
|
||||
Write-Host "(-ShowDeps:仅解析依赖,不执行打包)" -ForegroundColor Cyan
|
||||
return
|
||||
}
|
||||
|
||||
function Download-File([string]$Url, [string]$Dest) {
|
||||
if (-not $Force -and (Test-Path $Dest) -and (Get-Item $Dest).Length -gt 0) {
|
||||
Write-Host " cache hit: $Dest"
|
||||
@@ -92,6 +151,16 @@ if ($FromVenv) {
|
||||
-not (Test-Path (Join-Path $Venv "Lib\site-packages"))) {
|
||||
throw "venv 打包所需目录缺失:基础解释器($BasePy) 或 .venv\Lib\site-packages"
|
||||
}
|
||||
# 版本守卫:本地 .venv 必须与 requirements.txt 一致(唯一真源),否则打出来的包会跟随
|
||||
# 一个「没被记录」的版本。不一致时先 pip install -r requirements.txt 对齐再打包。
|
||||
$guard = Get-VenvDrift $Venv
|
||||
if (-not $guard.Found) {
|
||||
Write-Host " 未发现 .venv,跳过版本一致性校验" -ForegroundColor DarkGray
|
||||
} elseif ($guard.Drift.Count -gt 0) {
|
||||
throw ("本地 .venv 与 requirements.txt 版本不一致,请先 pip install -r requirements.txt 对齐:`n " + ($guard.Drift -join "`n "))
|
||||
} else {
|
||||
Write-Host " 版本守卫通过:.venv 与 requirements.txt 一致($($EnvPackages.Count) 个包)"
|
||||
}
|
||||
Write-Host "base interpreter: $BasePy"
|
||||
# 解释器 + 运行时 DLL + 标准库 + 扩展模块目录(DLLs/)
|
||||
foreach ($f in @("python.exe", "python311.dll", "python3.dll",
|
||||
|
||||
Reference in New Issue
Block a user