feat(electron-shell): 启动链路修复与执行/配置收口插件侧
- 启动链路 P1-P7 修复:预算对齐、完成事件推送、端口占用提示、前端阶段文案接管 - 静态缓存按 IS_FROZEN 区分开发/打包态,bootPhaseOwned 竞态修复 - 一键执行与参数配置统一收口到插件界面,定时任务引用 config_id - 环境包迁移到 %LOCALAPPDATA%\37duAutomation\python-env,重装零解压 - shell-updater:缓存包 sha256 校验、静默升级后自动拉起新版、自动清理旧安装包 - after-pack 钩子生成 shell.version 修复打包态版本识别 - 插件 xq0031/xq0045 迁移至 plugins/XQ0001-0100/ 号段分桶中文目录
This commit is contained in:
@@ -1,22 +1,27 @@
|
||||
# Build portable Python + environment package (python-env-<version>.zip)
|
||||
# Build portable Python + environment package (python-env-<version>.zip)
|
||||
# ============================================================================
|
||||
# Purpose: give the packaged Electron client a self-contained Python runtime so
|
||||
# plugins and platform-login no longer depend on an external Python install.
|
||||
# - Portable interpreter: python.org embeddable (self-contained)
|
||||
# - Portable interpreter: python.org embeddable (self-contained) [default]
|
||||
# - Dependencies: pinned to the versions validated in the project .venv
|
||||
# - Runtime subset: webhost/backend/{plugins,core,shared} (minimal for
|
||||
# plugin_runner protocol + platform login)
|
||||
# - Output: dist-env/python-env-<version>.zip + .sha256; by default also
|
||||
# installs into electron-shell/python-env/ for local dev (client probes it).
|
||||
# Usage (ASCII-safe, works on Windows PowerShell 5.1 with GBK codepage):
|
||||
# powershell -NoProfile -ExecutionPolicy Bypass -File scripts\build-python-env.ps1 [-EnvVersion 1.0.0] [-SkipLocal]
|
||||
# Needs: access to python.org / pypi.org (or an internal mirror via $PipIndex)
|
||||
# powershell -NoProfile -ExecutionPolicy Bypass -File scripts\build-python-env.ps1 [-EnvVersion 1.0.0] [-FromVenv] [-SkipLocal]
|
||||
# -FromVenv : 直接把本地 .venv 全量打包(基础解释器 python.exe/DLL/标准库 +
|
||||
# .venv\Lib\site-packages 全部依赖 + webhost 运行时子集)。不联网、
|
||||
# 复用已验证依赖版本,推荐日常构建;embeddable+pip 路径保留作备用。
|
||||
# Needs (embeddable mode only): access to python.org / pypi.org (or an internal
|
||||
# mirror via $PipIndex). FromVenv mode only needs the local .venv.
|
||||
# ============================================================================
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$EnvVersion = "1.0.0",
|
||||
[switch]$SkipLocal, # do NOT install into electron-shell/python-env/
|
||||
[switch]$Force # re-download embeddable / get-pip
|
||||
[switch]$FromVenv, # 从本地 .venv 全量打包(推荐,不联网)
|
||||
[switch]$SkipLocal, # do NOT install into electron-shell/python-env/
|
||||
[switch]$Force # re-download embeddable / get-pip
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -65,40 +70,73 @@ Write-Host "=== 37du portable python env build v$EnvVersion ===" -ForegroundColo
|
||||
|
||||
# ---------- 1. portable interpreter ----------
|
||||
New-Item -ItemType Directory -Force -Path $Build, $Dist, $DownloadDir | Out-Null
|
||||
Download-File $EmbedUrl $EmbedZip
|
||||
if (Test-Path $PyDir) { Remove-Item -Recurse -Force $PyDir }
|
||||
New-Item -ItemType Directory -Force -Path $PyDir | Out-Null
|
||||
Write-Host "extracting embeddable python ..."
|
||||
Expand-Archive -Path $EmbedZip -DestinationPath $PyDir -Force
|
||||
|
||||
if ($FromVenv) {
|
||||
# ---------- 1a. 从本地 .venv 全量打包(不联网):基础解释器 + venv site-packages ----------
|
||||
$Venv = Join-Path $Repo ".venv"
|
||||
$PyvenvCfg = Join-Path $Venv "pyvenv.cfg"
|
||||
$BasePy = ""
|
||||
if (Test-Path $PyvenvCfg) {
|
||||
$BasePy = (Get-Content $PyvenvCfg | Where-Object { $_ -match '^home\s*=' } |
|
||||
ForEach-Object { ($_ -split '=', 2)[1].Trim() } | Select-Object -First 1)
|
||||
}
|
||||
if (-not $BasePy -or -not (Test-Path (Join-Path $BasePy "python.exe")) -or
|
||||
-not (Test-Path (Join-Path $Venv "Lib\site-packages"))) {
|
||||
throw "venv 打包所需目录缺失:基础解释器($BasePy) 或 .venv\Lib\site-packages"
|
||||
}
|
||||
Write-Host "base interpreter: $BasePy"
|
||||
# 解释器 + 运行时 DLL + 标准库 + 扩展模块目录(DLLs/)
|
||||
foreach ($f in @("python.exe", "python311.dll", "python3.dll",
|
||||
"vcruntime140.dll", "vcruntime140_1.dll", "Lib", "DLLs")) {
|
||||
$s = Join-Path $BasePy $f
|
||||
if (Test-Path $s) { Copy-Item $s -Destination $PyDir -Recurse -Force }
|
||||
}
|
||||
# 精简标准库:剔除重/无关目录(base site-packages 随后由 .venv 全量覆盖)
|
||||
foreach ($drop in @("test", "tkinter", "idlelib", "ensurepip", "turtledemo", "site-packages")) {
|
||||
$p = Join-Path (Join-Path $PyDir "Lib") $drop
|
||||
if (Test-Path $p) { Remove-Item -Recurse -Force $p }
|
||||
}
|
||||
# .venv 的 site-packages 全量拷贝(已验证可用的插件/平台登录依赖,含 pip/setuptools)
|
||||
Write-Host "copying venv site-packages: $Venv\Lib\site-packages (全量)"
|
||||
Copy-Item (Join-Path $Venv "Lib\site-packages") -Destination (Join-Path $PyDir "Lib\site-packages") -Recurse -Force
|
||||
} else {
|
||||
# ---------- 1b. embeddable 便携解释器 + pip 依赖(需联网) ----------
|
||||
Download-File $EmbedUrl $EmbedZip
|
||||
Write-Host "extracting embeddable python ..."
|
||||
Expand-Archive -Path $EmbedZip -DestinationPath $PyDir -Force
|
||||
|
||||
# enable site-packages (pip / pywin32 .pth depend on 'import site')
|
||||
$Tag = ($PythonVersion.Split('.')[0..1] -join '')
|
||||
$Pth = Join-Path $PyDir "python$Tag._pth"
|
||||
Write-Host "enabling site + site-packages: $Pth"
|
||||
Set-Content -Path $Pth -Encoding ascii -Value @(
|
||||
"python$Tag.zip"
|
||||
"."
|
||||
"Lib\site-packages"
|
||||
""
|
||||
"# Enable site (pip / pywin32 .pth)"
|
||||
"import site"
|
||||
)
|
||||
|
||||
# ---------- 2. pip + dependencies ----------
|
||||
Download-File "https://bootstrap.pypa.io/get-pip.py" $GetPip
|
||||
Write-Host "bootstrapping pip ..."
|
||||
& $PyExe $GetPip --no-warn-script-location --disable-pip-version-check | Out-Host
|
||||
if ($LASTEXITCODE -ne 0) { throw "get-pip failed (exit $LASTEXITCODE)" }
|
||||
|
||||
Write-Host "installing pinned deps ($($Pinned.Count)) with --only-binary ..."
|
||||
$PipArgs = @("-m", "pip", "install", "--no-warn-script-location",
|
||||
"--disable-pip-version-check", "--only-binary=:all:")
|
||||
if ($PipIndex) { $PipArgs += "--index-url", $PipIndex }
|
||||
$PipArgs += $Pinned
|
||||
& $PyExe $PipArgs | Out-Host
|
||||
if ($LASTEXITCODE -ne 0) { throw "pip install failed (exit $LASTEXITCODE)" }
|
||||
}
|
||||
|
||||
$PyExe = Join-Path $PyDir "python.exe"
|
||||
if (-not (Test-Path $PyExe)) { throw "missing python.exe in embeddable" }
|
||||
|
||||
# enable site-packages (pip / pywin32 .pth depend on 'import site')
|
||||
$Tag = ($PythonVersion.Split('.')[0..1] -join '')
|
||||
$Pth = Join-Path $PyDir "python$Tag._pth"
|
||||
Write-Host "enabling site + site-packages: $Pth"
|
||||
Set-Content -Path $Pth -Encoding ascii -Value @(
|
||||
"python$Tag.zip"
|
||||
"."
|
||||
"Lib\site-packages"
|
||||
""
|
||||
"# Enable site (pip / pywin32 .pth)"
|
||||
"import site"
|
||||
)
|
||||
|
||||
# ---------- 2. pip + dependencies ----------
|
||||
Download-File "https://bootstrap.pypa.io/get-pip.py" $GetPip
|
||||
Write-Host "bootstrapping pip ..."
|
||||
& $PyExe $GetPip --no-warn-script-location --disable-pip-version-check | Out-Host
|
||||
if ($LASTEXITCODE -ne 0) { throw "get-pip failed (exit $LASTEXITCODE)" }
|
||||
|
||||
Write-Host "installing pinned deps ($($Pinned.Count)) with --only-binary ..."
|
||||
$PipArgs = @("-m", "pip", "install", "--no-warn-script-location",
|
||||
"--disable-pip-version-check", "--only-binary=:all:")
|
||||
if ($PipIndex) { $PipArgs += "--index-url", $PipIndex }
|
||||
$PipArgs += $Pinned
|
||||
& $PyExe $PipArgs | Out-Host
|
||||
if ($LASTEXITCODE -ne 0) { throw "pip install failed (exit $LASTEXITCODE)" }
|
||||
if (-not (Test-Path $PyExe)) { throw "missing python.exe in build dir" }
|
||||
|
||||
# copy pywin32 DLLs next to the interpreter (no postinstall / PATH dependency)
|
||||
$PyWin32Sys = Join-Path $PyDir "Lib\site-packages\pywin32_system32"
|
||||
|
||||
Reference in New Issue
Block a user