feat: 商业版第一步·个人版包收尾(决策 228)——build_portable 三坑修复(cp315 cffi 版本错配→本地 wheels 离线安装、get-pip 在线自举卡死弃用、--no-cache-dir 绕权限)、gate 放行 /api/version* 版本状态口、强制更新冒烟断言、决策 228 与协作改进补记、误入库 pip 临时文件清理

This commit is contained in:
lianjianwei2024
2026-10-27 12:58:53 +08:00
parent 380a39f8db
commit 2726454298
10 changed files with 572 additions and 4511 deletions

View File

@@ -197,6 +197,35 @@ def write_license_build_config(app_target, app_version="0.0.0", info_url=None,
% (len(keys), app_version, product_id, len(integrity or {})))
def prepare_wheels(cache):
"""依赖 wheel 本地缓存:一次下载、永久复用,包内离线安装(构建零网络依赖)。
版本坑(2026-10-27 实证):构建机 Python 3.15 按自身版本选 wheel,cffi 会下成
cp315 专属 wheel(embeddable 3.13 加载即 "No module named '_cffi_backend'")。
依赖里**只有 cffi 是单版本专属**:cryptography=cp39-abi3 通用、pythonnet=多版本
标签 wheel(含 cp313)、其余为纯 py wheel/sdist——删 cp315 的 cffi 后按 3.13
交叉补一个即可。若将来依赖清单变更出现新的单版本专属包,在这里同样处理。
"""
wheels = cache / "wheels"
wheels.mkdir(parents=True, exist_ok=True)
if not list(wheels.glob("cryptography-*.whl")):
log("下载依赖 wheel 到本地缓存(一次下载,永久复用)…")
subprocess.run([sys.executable, "-m", "pip", "download", "-q", "-d", str(wheels),
"--timeout", "30", "--retries", "8", "setuptools"] + DEPS, check=True)
for bad in list(wheels.glob("cffi-*-cp315-*.whl")) + list(wheels.glob("cffi-*-cp314-*.whl")):
log("剔除版本不符 wheel:%s" % bad.name)
bad.unlink()
if not list(wheels.glob("cffi-*-cp313-*.whl")):
log("按 embeddable %s 交叉补 cffi wheel…" % EMBED_PY)
subprocess.run([sys.executable, "-m", "pip", "download", "-q", "-d", str(wheels),
"--platform", "win_amd64", "--python-version", EMBED_PY,
"--implementation", "cp", "--abi", "cp313",
"--only-binary=:all:", "--no-deps", "cffi"], check=True)
if not list(wheels.glob("cffi-*-cp313-*.whl")):
raise RuntimeError("cffi cp313 wheel 未能就位(缓存 %s)" % wheels)
return wheels
def main():
if os.name != "nt":
raise RuntimeError("请在 Windows x64 上构建")
@@ -250,31 +279,31 @@ def main():
sp = py_dir / "Lib" / "site-packages"
cache = OUT / "_cache"
cache.mkdir(parents=True, exist_ok=True)
# 包内自举 pip:下载 pip wheel(纯 py、平台无关,走构建机同一 index 秒级),
# 直接以 whl 内的 pip 模块运行——不依赖 get-pip 的在线 bootstrap(2026-10-27
# 实测:get-pip 从 bootstrap.pypa.io 下载在本网络下会无限卡死)。
# 包内自举 pip(离线 whl 入口,不用 get-pip 在线 bootstrap——该域在本网络会卡死)
whl_dir = cache / "pipwheel"
whl_dir.mkdir(parents=True, exist_ok=True)
wheels = list(whl_dir.glob("pip-*.whl"))
if not wheels:
log("下载 pip wheel(构建机 index)…")
subprocess.run([sys.executable, "-m", "pip", "download", "-q",
"-d", str(whl_dir), "pip"], check=True)
"-d", str(whl_dir), "--timeout", "30", "--retries", "8",
"pip"], check=True)
wheels = list(whl_dir.glob("pip-*.whl"))
if not wheels:
raise RuntimeError("pip wheel 下载失败(缓存 %s)" % whl_dir)
pip_mod = "%s/pip" % wheels[0]
# 网络韧性(2026-10-27 实测):files.pythonhosted.org 偶发 15s 读超时,pip 静默
# 重试在 capture 下形似卡死——显式拉长超时/重试,装不完就真报错。
PIP_NET = ["--timeout", "30", "--retries", "8"]
log("包内 python 自举 pip 并补 setuptools …")
# 依赖全走本地 wheels 缓存离线安装(--no-index):网络时好时坏不再影响构建;
# setuptools 先装(pywebview 的 proxy_tools 依赖是纯 py sdist,构建需要它)。
wheels_dir = prepare_wheels(cache)
log("包内离线安装依赖 ← %s" % wheels_dir)
# --no-cache-dir:包内 python 写用户级 pip 缓存会 WinError 5 拒绝访问(2026-10-27 实证)
subprocess.run([str(py_dir / "python.exe"), pip_mod, "install",
"--disable-pip-version-check"] + PIP_NET + ["setuptools"],
check=True)
log("安装依赖 → python/Lib/site-packages(包内 3.13 自装,版本匹配)")
"--no-index", "--find-links", str(wheels_dir), "--no-cache-dir",
"--disable-pip-version-check", "setuptools"], check=True)
subprocess.run([str(py_dir / "python.exe"), pip_mod, "install",
"--no-index", "--find-links", str(wheels_dir), "--no-cache-dir",
"--disable-pip-version-check", "--no-warn-script-location"]
+ PIP_NET + DEPS, check=True)
+ DEPS, check=True)
# 3) 应用代码 + 空数据目录 + 启动器
app_target = PACKAGE / "CostReview" / "app"
@@ -340,7 +369,7 @@ def main():
"assert (biz==403) if locked else (biz==200), '门禁行为不符:can_run=%s biz=%s' % (d.get('can_run'), biz)\n"
"# 强制更新冒烟(2026-10-27 5.9):正式发版包必须烧出版本号;内测包=旁路。\n"
"vi=json.loads(urllib.request.urlopen('http://127.0.0.1:8399/api/version_info',timeout=5).read())\n"
"vd=vi.get('data') or {}\n"
"vd=vi.get('data') or vi\n"
"bver=os.environ.get('PR_BUILD_VER','')\n"
"if bver:\n"
" assert vd.get('current')==bver, 'version_info current=%r 应=%r' % (vd.get('current'), bver)\n"