源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
This commit is contained in:
commit
1a3a4ccde1
4652 files changed
+1891610
No files matched your search
@@ -0,0 +1,98 @@
|
||||
# QwenPaw Desktop packaging scripts
|
||||
|
||||
> ⚠️ **Legacy (rollback-only).** These conda-pack based packaging scripts have
|
||||
> been superseded by the **Tauri** desktop build (see `console/src-tauri/` and
|
||||
> `scripts/pack-tauri/`). They are kept only for short-term rollback and are no
|
||||
> longer used by the release pipeline. For the current desktop app, refer to the
|
||||
> [Desktop Application Guide](https://qwenpaw.agentscope.io/docs/desktop).
|
||||
|
||||
One-click build: each script first builds a **wheel** via
|
||||
`scripts/wheel_build.sh` (includes the console frontend), then uses a
|
||||
**temporary conda environment** and **conda-pack** (no current dev env).
|
||||
Dependencies follow `pyproject.toml`.
|
||||
|
||||
- **Windows**: wheel → conda-pack → unpack → NSIS installer (`.exe`)
|
||||
- **macOS**: wheel → conda-pack → unpack into `.app` → optional zip
|
||||
|
||||
## System Requirements
|
||||
|
||||
- **Windows**: Windows 10 or later
|
||||
- **macOS**: macOS 14 (Sonoma) or later, Apple Silicon (M1/M2/M3/M4) recommended
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- **conda** (Miniconda/Anaconda) on PATH
|
||||
- **Node.js / npm** (for the console frontend)
|
||||
- (Windows only) **NSIS**: `makensis` on PATH
|
||||
- **Icons**: Pre-generated `icon.ico` (Windows) and `icon.icns` (macOS) are included in `scripts/pack/assets/`
|
||||
|
||||
## One-click build
|
||||
|
||||
From the **repo root**:
|
||||
|
||||
**macOS**
|
||||
```bash
|
||||
bash ./scripts/pack/build_macos.sh
|
||||
# Output: dist/QwenPaw.app
|
||||
|
||||
CREATE_ZIP=1 bash ./scripts/pack/build_macos.sh # also create .zip
|
||||
```
|
||||
|
||||
**Windows (PowerShell)**
|
||||
```powershell
|
||||
./scripts/pack/build_win.ps1
|
||||
# Output: dist/QwenPaw-Setup-<version>.exe
|
||||
# Creates two launchers:
|
||||
# - QwenPaw Desktop.vbs (silent, no console window)
|
||||
# - QwenPaw Desktop (Debug).bat (shows console for troubleshooting)
|
||||
# Note: Pre-compiles all Python files to .pyc for faster startup
|
||||
```
|
||||
|
||||
## Run from terminal and see logs (macOS)
|
||||
|
||||
If the .app crashes on double-click, run it from Terminal to see the full error and logs:
|
||||
|
||||
```bash
|
||||
# From repo root; force packed env only (no system conda / PYTHONPATH). Adjust path if needed.
|
||||
APP_ENV="$(pwd)/dist/QwenPaw.app/Contents/Resources/env"
|
||||
PYTHONNOUSERSITE=1 PYTHONPATH= PYTHONHOME="$APP_ENV" "$APP_ENV/bin/python" -m qwenpaw desktop
|
||||
```
|
||||
|
||||
The `PYTHONNOUSERSITE=1` prevents Python from loading packages from `~/.local/lib/pythonX.Y/site-packages`, which can conflict with the packaged environment. All stdout/stderr (including Python tracebacks) will appear in the terminal. Use this to debug startup errors or to run with `--log-level debug`.
|
||||
|
||||
When you **double-click** the .app and nothing appears, the launcher writes stderr/stdout to `~/.qwenpaw/desktop.log`. Inspect that file for errors.
|
||||
|
||||
On first launch macOS may ask for “Desktop” or “Files and Folders” access: click **Allow** so the app can run properly; if you click Don’t Allow, the window may close.
|
||||
|
||||
## macOS: if “Apple cannot verify” / Gatekeeper blocks the app
|
||||
|
||||
When users download the QwenPaw macOS app (e.g. from Releases) as a `.app` (in a zip), macOS may show: *"Apple cannot verify that 'QwenPaw' contains no malicious software"*. The app is not notarized. They can still open it as follows:
|
||||
|
||||
- **Right-click to open (recommended)**
|
||||
Right-click (or Control+click) the QwenPaw app → **Open** → in the dialog click **Open** again. Gatekeeper will allow it; after that double-click works as usual.
|
||||
|
||||
- **Allow in System Settings**
|
||||
If still blocked, go to **System Settings → Privacy & Security**, find the message like *"QwenPaw was blocked because it is from an unidentified developer"*, and click **Open Anyway** or **Allow**.
|
||||
|
||||
- **Remove quarantine attribute (not recommended for most users)**
|
||||
In Terminal: `xattr -cr /Applications/QwenPaw.app` (or the path to the `.app` after unzipping). This clears the download quarantine flag; less safe than right-click → Open.
|
||||
|
||||
## CI
|
||||
|
||||
`.github/workflows/desktop-release.yml`:
|
||||
|
||||
- **Triggers**: Release publish or manual workflow_dispatch
|
||||
- **Windows**: Build console → temporary conda env + conda-pack → NSIS → upload artifact
|
||||
- **macOS**: Build console → temporary conda env + conda-pack → .app → zip → upload artifact
|
||||
- **Release**: When triggered by a release, uploads the Windows installer and macOS zip as release assets
|
||||
|
||||
## Script reference
|
||||
|
||||
| File | Description |
|
||||
|------|-------------|
|
||||
| `build_common.py` | Create temporary conda env, install `qwenpaw[full]` from a wheel, conda-pack; produces archive. |
|
||||
| `build_macos.sh` | One-click: build wheel → build_common → unpack into QwenPaw.app; optional zip. |
|
||||
| `build_win.ps1` | One-click: build wheel → build_common → unpack → create VBS/BAT launchers → makensis installer. |
|
||||
| `desktop.nsi` | NSIS script: pack `dist/win-unpacked`, add icons, and create shortcuts. |
|
||||
| `assets/icon.ico` | Pre-generated Windows icon (installer and shortcuts). |
|
||||
| `assets/icon.icns` | Pre-generated macOS icon (app bundle). |
|
||||
@@ -0,0 +1,95 @@
|
||||
# QwenPaw Desktop 打包脚本
|
||||
|
||||
> ⚠️ **旧版(仅用于回滚)。** 这套基于 conda-pack 的打包脚本已被 **Tauri**
|
||||
> 桌面版构建取代(详见 `console/src-tauri/` 与 `scripts/pack-tauri/`),仅作
|
||||
> 短期回滚保留,发布流程已不再使用。当前桌面应用请参考
|
||||
> [桌面应用指南](https://qwenpaw.agentscope.io/docs/desktop)。
|
||||
|
||||
一键打包:脚本会先运行 `scripts/wheel_build.sh` 构建 **wheel**
|
||||
(包含 console 前端产物),再用 **临时 conda 环境** + **conda-pack**
|
||||
(不依赖当前开发环境)。依赖以 `pyproject.toml` 为准。
|
||||
|
||||
- **Windows**: wheel → conda-pack → 解压 → NSIS 安装包 (`.exe`)
|
||||
- **macOS**: wheel → conda-pack → 解压到 `.app` → 可选打 zip
|
||||
|
||||
## 系统要求
|
||||
|
||||
- **Windows**: Windows 10 或更高版本
|
||||
- **macOS**: macOS 14 (Sonoma) 或更高版本,推荐 Apple Silicon (M1/M2/M3/M4)
|
||||
|
||||
## 前置
|
||||
|
||||
- **conda**(Miniconda/Anaconda)在 PATH
|
||||
- **Node.js / npm**(用于构建 console 前端)
|
||||
- (仅 Windows)**NSIS**:`makensis` 在 PATH
|
||||
- **图标**:预生成的 `icon.ico` (Windows) 和 `icon.icns` (macOS) 已包含在 `scripts/pack/assets/` 中
|
||||
|
||||
## 一键打包
|
||||
|
||||
在**仓库根目录**执行:
|
||||
|
||||
**macOS**
|
||||
```bash
|
||||
bash ./scripts/pack/build_macos.sh
|
||||
# 产出: dist/QwenPaw.app
|
||||
|
||||
CREATE_ZIP=1 bash ./scripts/pack/build_macos.sh # 同时生成 .zip
|
||||
```
|
||||
|
||||
**Windows (PowerShell)**
|
||||
```powershell
|
||||
./scripts/pack/build_win.ps1
|
||||
# 产出: dist/QwenPaw-Setup-<version>.exe
|
||||
# 创建两个启动器:
|
||||
# - QwenPaw Desktop.vbs (静默启动,无终端窗口)
|
||||
# - QwenPaw Desktop (Debug).bat (显示终端,便于调试)
|
||||
```
|
||||
|
||||
## 从终端启动并查看日志(macOS)
|
||||
|
||||
如果双击 .app 会闪退,可以在终端里运行以查看完整报错和日志:
|
||||
|
||||
```bash
|
||||
# 在仓库根目录执行,强制只用打包环境(不用系统 conda / PYTHONPATH)。路径按需改。
|
||||
APP_ENV="$(pwd)/dist/QwenPaw.app/Contents/Resources/env"
|
||||
PYTHONNOUSERSITE=1 PYTHONPATH= PYTHONHOME="$APP_ENV" "$APP_ENV/bin/python" -m qwenpaw desktop
|
||||
```
|
||||
|
||||
`PYTHONNOUSERSITE=1` 可防止 Python 加载 `~/.local/lib/pythonX.Y/site-packages` 中的包,避免与打包环境冲突。所有标准输出和错误(包括 Python traceback)都会打在终端里;可加 `--log-level debug` 查看更详细日志。
|
||||
|
||||
若**双击** .app 没有任何窗口出现,启动器会把 stderr/stdout 写入 `~/.qwenpaw/desktop.log`,可打开该文件查看报错。
|
||||
|
||||
首次打开时,macOS 可能弹出「请求访问桌面的文件」:请点**允许**,否则部分功能可能不可用或窗口会关闭。
|
||||
|
||||
## macOS:提示「无法验证开发者」/ Gatekeeper 拦截时怎么打开
|
||||
|
||||
用户从 Release 等渠道下载的 QwenPaw macOS 应用(zip 内的 .app)未经过 Apple 公证,可能看到「Apple 无法验证“QwenPaw”是否包含可能危害 Mac 安全或泄漏隐私的恶意软件」。可按以下方式打开:
|
||||
|
||||
- **右键打开(推荐)**
|
||||
在 QwenPaw 应用上 **右键(或 Control + 点击)** → 选 **「打开」** → 在弹窗里再点一次 **「打开」**。即表示你确认运行该应用,Gatekeeper 会放行,之后双击即可正常打开。
|
||||
|
||||
- **在系统设置里放行**
|
||||
若仍被拦截,进入 **系统设置 → 隐私与安全性**,往下找到类似「已阻止使用 QwenPaw,因为无法验证开发者」的提示,点 **「仍要打开」** 或 **「允许」** 即可。
|
||||
|
||||
- **用终端去掉隔离属性(不推荐普通用户)**
|
||||
在终端执行:`xattr -cr /Applications/QwenPaw.app`(或解压后 .app 的实际路径)。会去掉「从互联网下载」的隔离标记,一般就不再弹恶意软件提示,但不如「右键 → 打开」安全、可控。
|
||||
|
||||
## CI
|
||||
|
||||
`.github/workflows/desktop-release.yml`:
|
||||
|
||||
- **触发**: Release 发布 或 手动 workflow_dispatch
|
||||
- **Windows**: 构建 console → 临时 conda 环境 + conda-pack → NSIS → 上传 artifact
|
||||
- **macOS**: 构建 console → 临时 conda 环境 + conda-pack → .app → zip → 上传 artifact
|
||||
- **Release**: 若由 release 触发,则把 Windows 安装包与 macOS zip 上传到该 Release 的附件
|
||||
|
||||
## 脚本说明
|
||||
|
||||
| 文件 | 说明 |
|
||||
|------|------|
|
||||
| `build_common.py` | 创建临时 conda 环境,从 wheel 安装 `qwenpaw[full]`,conda-pack 产出归档 |
|
||||
| `build_macos.sh` | 一键:构建 wheel → build_common → 解压到 QwenPaw.app;可选打 zip |
|
||||
| `build_win.ps1` | 一键:构建 wheel → build_common → 解压 → 创建 VBS/BAT 启动器 → makensis 安装包 |
|
||||
| `desktop.nsi` | NSIS 脚本:打包 `dist/win-unpacked`,添加图标,创建快捷方式 |
|
||||
| `assets/icon.ico` | 预生成的 Windows 图标(安装包和快捷方式使用) |
|
||||
| `assets/icon.icns` | 预生成的 macOS 图标(应用包使用) |
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="1024" height="1024" viewBox="0 0 1024 1024"><defs><clipPath id="master_svg0_145_29064"><rect x="0" y="0" width="1024" height="1024" rx="192"/></clipPath><clipPath id="master_svg1_145_29067"><rect x="191" y="81" width="642" height="861.9312133789062" rx="0"/></clipPath></defs><g clip-path="url(#master_svg0_145_29064)"><rect x="0" y="0" width="1024" height="1024" rx="192" fill="#FCFAF8" fill-opacity="1"/><g clip-path="url(#master_svg1_145_29067)"><path d="M495.2844617351198,922.9861783496094C663.2927917351199,922.9861783496094,799.4904617351198,791.1350683496094,799.4904617351198,628.4886183496094C799.4904617351198,465.8420983496094,663.2927917351199,333.9910583496094,495.2844617351198,333.9910583496094C327.2761517351198,333.9910583496094,191.07847173511982,465.8420983496094,191.07847173511982,628.4886183496094C191.07847173511982,791.1350683496094,327.2761517351198,922.9861783496094,495.2844617351198,922.9861783496094ZM495.28584173511985,796.3202783496095C591.0325417351198,796.3202783496095,668.6505817351199,721.1793783496094,668.6505817351199,628.4883683496093C668.6505817351199,535.7973483496094,591.0325417351198,460.65642834960937,495.28584173511985,460.65642834960937C399.53915173511984,460.65642834960937,321.9211517351198,535.7973483496094,321.9211517351198,628.4883683496093C321.9211517351198,721.1793783496094,399.53915173511984,796.3202783496095,495.28584173511985,796.3202783496095Z" fill-rule="evenodd" fill="#000000" fill-opacity="1"/><path d="M485.0743194589844,251.25908713623048C492.3848264589844,258.3831971362305,501.07937645898437,263.98323713623046,511.15793645898435,268.0592471362305C521.2364884589844,272.1352171362305,532.1667634589844,274.19093713623045,543.9487534589844,274.19093713623045C555.7307514589844,274.19093713623045,566.9449454589844,272.09975713623044,576.9879954589844,267.95290713623046C587.0665554589843,263.77058713623046,595.7966154589844,258.09966713623044,603.2135654589844,250.86922713623048C610.6305254589844,243.63878713623046,616.4150654589844,235.23872713623047,620.6026354589844,225.66901713623048C624.7902354589844,216.09930713623046,626.8485454589844,205.7853011362305,626.8485454589844,194.79787413623046L626.8485454589844,194.23078113623046C626.8485454589844,183.24334713623045,624.7547654589844,172.92934413623047,620.6026354589844,163.35964213623046C616.4150654589844,153.75450113623046,610.6660354589844,145.42531813623046,603.3555254589844,138.30120813623046C596.0450154589844,131.17710013623048,587.3504554589844,125.57705613623047,577.2719154589844,121.50107333623046C567.1933554589843,117.42509053623047,556.2630694589843,115.36937713623047,544.4810794589844,115.36937713623047C532.6991044589844,115.36937713623047,521.4848974589844,117.46053333623047,511.4063494589844,121.60740323623047C501.3277894589844,125.78971613623047,492.5977384589844,131.46064713623048,485.1807764589844,138.69108913623046C477.76381845898436,145.92152813623048,471.9792704589844,154.28614813623045,467.7916941589844,163.89129613623047C463.6041195589844,173.46099813623047,461.5103454589844,183.77500913623047,461.5103454589844,194.76244313623047L461.5103454589844,195.32952913623046C461.5103454589844,206.35240913623045,463.6041195589844,216.63096713623048,467.7916941589844,226.23611713623046C471.9792704589844,235.80582713623045,477.7283234589844,244.17046713623046,485.0388264589844,251.25909713623048L485.0743194589844,251.25908713623048Z" fill="#FF9D4D" fill-opacity="1" style="mix-blend-mode:passthrough" transform="matrix(0.9901291728019714,-0.14083673059940338,0.14062289893627167,0.9899662137031555,-11.668087391240647,66.15519986762956)"/><path d="M270.4956069135742,294.62703757568363C277.8045499135742,301.7511475756836,286.4972269135742,307.3512075756836,296.5736309135742,311.42719757568364C306.6500319135742,315.5031675756836,317.5779649135742,317.55888757568357,329.3574299135742,317.55888757568357C341.1368939135742,317.55888757568357,352.34865891357424,315.46770757568356,362.3895789135742,311.2853775756836C372.4659889135742,307.1030975756836,381.1941289135742,301.4321675756836,388.6095189135742,294.2017175756836C396.0249089135742,286.9712775756836,401.8082089135742,278.6066575756836,405.9948789135742,269.0015075756836C410.18153891357423,259.4318075756836,412.2749089135742,249.11780557568358,412.2749089135742,238.1303715756836L412.2749089135742,237.5632855756836C412.2749089135742,226.5758665756836,410.18153891357423,216.2972905756836,405.9948789135742,206.69214657568358C401.8082089135742,197.08700557568358,396.06038891357423,188.7578235756836,388.7514289135742,181.6691565756836C381.4425089135742,174.5450505756836,372.74981891357425,168.9450035756836,362.6734289135742,164.8690218756836C352.5970289135742,160.79304027568358,341.6691059135742,158.7373275756836,329.8896409135742,158.7373275756836C318.1101689135742,158.7373275756836,306.8984029135742,160.8284842756836,296.82199891357425,165.010798975Line truncated
|
||||
|
After Width: | Height: | Size: 7.9 KiB |
@@ -0,0 +1,251 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# pylint:disable=too-many-statements
|
||||
"""
|
||||
Create a temporary conda env, install QwenPaw from a wheel, run conda-pack.
|
||||
Used by build_macos.sh and build_win.ps1. Run from repo root.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||
ENV_PREFIX = "qwenpaw_pack_"
|
||||
|
||||
# Packages affected by conda-unpack bug on Windows (conda-pack Issue #154)
|
||||
# conda-unpack modifies Python source files to replace path prefixes, but uses
|
||||
# simple byte replacement without considering Python syntax. This corrupts
|
||||
# string literals containing backslash escapes, causing SyntaxError.
|
||||
# Example: "\\\\?\\" (correct) -> "\\" (SyntaxError: unterminated string)
|
||||
# Solution: After conda-unpack, reinstall these packages to restore correct files
|
||||
# See: issue.md and https://github.com/conda/conda-pack/issues/154
|
||||
CONDA_UNPACK_AFFECTED_PACKAGES = [
|
||||
"huggingface_hub", # file_download.py, _local_folder.py use Windows long path prefix
|
||||
"discord.py", # ARG_NAME_SUBREGEX contains \\?\* which gets corrupted
|
||||
]
|
||||
|
||||
|
||||
def _conda_exe() -> str:
|
||||
"""Resolve conda executable (required on Windows where 'conda' is a batch)."""
|
||||
exe = os.environ.get("CONDA_EXE")
|
||||
if exe:
|
||||
return exe
|
||||
return "conda"
|
||||
|
||||
|
||||
def _run(
|
||||
cmd: list[str],
|
||||
cwd: Path | None = None,
|
||||
env: dict[str, str] | None = None,
|
||||
) -> None:
|
||||
"""Run command with optional environment variable overrides."""
|
||||
run_env = os.environ.copy()
|
||||
if env:
|
||||
run_env.update(env)
|
||||
subprocess.run(cmd, cwd=cwd or REPO_ROOT, env=run_env, check=True)
|
||||
|
||||
|
||||
def _pick_wheel(wheel_arg: str | None) -> Path:
|
||||
if wheel_arg:
|
||||
wheel_path = Path(wheel_arg).expanduser()
|
||||
if not wheel_path.is_absolute():
|
||||
wheel_path = (REPO_ROOT / wheel_path).resolve()
|
||||
if not wheel_path.exists():
|
||||
raise FileNotFoundError(f"Wheel not found: {wheel_path}")
|
||||
return wheel_path
|
||||
|
||||
wheels = sorted(
|
||||
(REPO_ROOT / "dist").glob("qwenpaw-*.whl"),
|
||||
key=lambda p: p.stat().st_mtime,
|
||||
reverse=True,
|
||||
)
|
||||
if not wheels:
|
||||
raise FileNotFoundError(
|
||||
"No wheel found in dist/. Run: bash scripts/wheel_build.sh",
|
||||
)
|
||||
return wheels[0]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Conda-pack QwenPaw (temp env).",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
"-o",
|
||||
required=True,
|
||||
help="Output archive path (e.g. .tar.gz)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--format",
|
||||
"-f",
|
||||
default="infer",
|
||||
choices=["infer", "zip", "tar.gz", "tgz"],
|
||||
help="Archive format (default: infer from --output extension)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--python",
|
||||
default="3.11",
|
||||
help="Python version for conda env (default: 3.11)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--wheel",
|
||||
default=None,
|
||||
help=(
|
||||
"Wheel path to install. If omitted, pick the newest "
|
||||
"dist/qwenpaw-*.whl."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--cache-wheels",
|
||||
action="store_true",
|
||||
help=(
|
||||
"Download wheels for packages affected by conda-unpack bug. "
|
||||
"Cached to .cache/conda_unpack_wheels/ for later reinstall."
|
||||
),
|
||||
)
|
||||
args = parser.parse_args()
|
||||
out_path = Path(args.output).resolve()
|
||||
out_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
wheel_path = _pick_wheel(args.wheel)
|
||||
wheel_uri = wheel_path.resolve().as_uri()
|
||||
env_name = (
|
||||
f"{ENV_PREFIX}{''.join(random.choices(string.ascii_lowercase, k=8))}"
|
||||
)
|
||||
|
||||
conda = _conda_exe()
|
||||
try:
|
||||
_run(
|
||||
[
|
||||
conda,
|
||||
"create",
|
||||
"-n",
|
||||
env_name,
|
||||
f"python={args.python}",
|
||||
# OpenSSL 3.5.7 has a regression (upstream commit 738688d76206
|
||||
# reworking asn1_d2i_read_bio) that breaks
|
||||
# ssl.SSLContext.load_verify_locations(cadata=<DER>), which
|
||||
# _load_windows_store_certs relies on. aiohttp then fails at
|
||||
# import time and the desktop backend never starts. See #5086.
|
||||
"openssl<3.5.7",
|
||||
"pip",
|
||||
"-y",
|
||||
],
|
||||
)
|
||||
# Install qwenpaw with all dependencies
|
||||
# Scope CMAKE_ARGS to this specific command to avoid affecting other
|
||||
# CMake-based packages. Only set if we need to compile from source.
|
||||
install_env = {}
|
||||
|
||||
_run(
|
||||
[
|
||||
conda,
|
||||
"run",
|
||||
"-n",
|
||||
env_name,
|
||||
"python",
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
f"qwenpaw[full] @ {wheel_uri}",
|
||||
],
|
||||
env=install_env,
|
||||
)
|
||||
print("Verifying certifi is installed (required for SSL)...")
|
||||
_run(
|
||||
[
|
||||
conda,
|
||||
"run",
|
||||
"-n",
|
||||
env_name,
|
||||
"python",
|
||||
"-c",
|
||||
"import certifi; print(f'certifi OK: {certifi.where()}')",
|
||||
],
|
||||
)
|
||||
if args.cache_wheels:
|
||||
# Store outside dist/ to avoid being deleted by wheel_build cleanup
|
||||
wheels_cache = REPO_ROOT / ".cache" / "conda_unpack_wheels"
|
||||
wheels_cache.mkdir(parents=True, exist_ok=True)
|
||||
print(
|
||||
f"Caching wheels for conda-unpack bug workaround to "
|
||||
f"{wheels_cache}",
|
||||
)
|
||||
_run(
|
||||
[
|
||||
conda,
|
||||
"run",
|
||||
"-n",
|
||||
env_name,
|
||||
"python",
|
||||
"-m",
|
||||
"pip",
|
||||
"download",
|
||||
*CONDA_UNPACK_AFFECTED_PACKAGES,
|
||||
"-d",
|
||||
str(wheels_cache),
|
||||
],
|
||||
)
|
||||
# pip may uninstall/reinstall files owned by conda while resolving
|
||||
# qwenpaw[full]. Restore conda-managed packaging tools before packing.
|
||||
_run(
|
||||
[
|
||||
conda,
|
||||
"run",
|
||||
"-n",
|
||||
env_name,
|
||||
conda,
|
||||
"install",
|
||||
"-y",
|
||||
"--force-reinstall",
|
||||
"pip",
|
||||
"setuptools",
|
||||
"wheel",
|
||||
],
|
||||
)
|
||||
_run(
|
||||
[
|
||||
conda,
|
||||
"run",
|
||||
"-n",
|
||||
env_name,
|
||||
conda,
|
||||
"install",
|
||||
"-y",
|
||||
"conda-pack",
|
||||
],
|
||||
)
|
||||
if out_path.exists():
|
||||
out_path.unlink()
|
||||
pack_cmd = [
|
||||
conda,
|
||||
"run",
|
||||
"-n",
|
||||
env_name,
|
||||
"conda-pack",
|
||||
"-n",
|
||||
env_name,
|
||||
"-o",
|
||||
str(out_path),
|
||||
"-f",
|
||||
]
|
||||
if args.format != "infer":
|
||||
pack_cmd.extend(["--format", args.format])
|
||||
_run(pack_cmd)
|
||||
print(f"Packed to {out_path}")
|
||||
finally:
|
||||
try:
|
||||
_run([conda, "env", "remove", "-n", env_name, "-y"])
|
||||
except Exception as e:
|
||||
print(f"Warning: Failed to remove temp env {env_name}: {e}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,184 @@
|
||||
#!/usr/bin/env bash
|
||||
# One-click build: console -> conda-pack -> QwenPaw.app. Run from repo root.
|
||||
# Requires: conda, node/npm (for console). Optional: icon.icns in assets/.
|
||||
|
||||
set -e
|
||||
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
cd "$REPO_ROOT"
|
||||
PACK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
DIST="${DIST:-dist}"
|
||||
ARCHIVE="${DIST}/qwenpaw-env.tar.gz"
|
||||
APP_NAME="QwenPaw"
|
||||
APP_DIR="${DIST}/${APP_NAME}.app"
|
||||
|
||||
echo "== Building wheel (includes console frontend) =="
|
||||
# Skip wheel_build if dist already has a wheel for current version
|
||||
VERSION_FILE="${REPO_ROOT}/src/qwenpaw/__version__.py"
|
||||
CURRENT_VERSION=""
|
||||
if [[ -f "${VERSION_FILE}" ]]; then
|
||||
CURRENT_VERSION="$(
|
||||
sed -n 's/^__version__[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' \
|
||||
"${VERSION_FILE}" 2>/dev/null
|
||||
)"
|
||||
fi
|
||||
if [[ -n "${CURRENT_VERSION}" ]]; then
|
||||
shopt -s nullglob
|
||||
whls=("${REPO_ROOT}/dist/qwenpaw-${CURRENT_VERSION}-"*.whl)
|
||||
if [[ ${#whls[@]} -gt 0 ]]; then
|
||||
echo "dist/ already has wheel for version ${CURRENT_VERSION}, skipping."
|
||||
else
|
||||
# Clean up old wheels to avoid confusion
|
||||
old_whls=("${REPO_ROOT}/dist/qwenpaw-"*.whl)
|
||||
if [[ ${#old_whls[@]} -gt 0 ]]; then
|
||||
echo "Removing old wheel files: ${old_whls[*]}"
|
||||
rm -f "${old_whls[@]}"
|
||||
fi
|
||||
bash scripts/wheel_build.sh
|
||||
fi
|
||||
else
|
||||
bash scripts/wheel_build.sh
|
||||
fi
|
||||
|
||||
echo "== Building conda-packed env =="
|
||||
python "${PACK_DIR}/build_common.py" --output "$ARCHIVE" --format tar.gz
|
||||
|
||||
echo "== Building .app bundle =="
|
||||
rm -rf "$APP_DIR"
|
||||
mkdir -p "${APP_DIR}/Contents/MacOS"
|
||||
mkdir -p "${APP_DIR}/Contents/Resources"
|
||||
|
||||
# Unpack conda env into Resources/env
|
||||
mkdir -p "${APP_DIR}/Contents/Resources/env"
|
||||
tar -xzf "$ARCHIVE" -C "${APP_DIR}/Contents/Resources/env" --strip-components=0
|
||||
|
||||
# Fix paths for portability (required or app will crash on launch)
|
||||
if [[ -x "${APP_DIR}/Contents/Resources/env/bin/conda-unpack" ]]; then
|
||||
(cd "${APP_DIR}/Contents/Resources/env" && ./bin/conda-unpack)
|
||||
fi
|
||||
|
||||
# Launcher: force packed env; when no TTY log to ~/.qwenpaw/desktop.log (no exec so we see errors)
|
||||
cat > "${APP_DIR}/Contents/MacOS/${APP_NAME}" << 'LAUNCHER'
|
||||
#!/usr/bin/env bash
|
||||
ENV_DIR="$(cd "$(dirname "$0")/../Resources/env" && pwd)"
|
||||
LOG="$HOME/.qwenpaw/desktop.log"
|
||||
unset PYTHONPATH
|
||||
export PYTHONHOME="$ENV_DIR"
|
||||
export PYTHONNOUSERSITE=1
|
||||
export QWENPAW_DESKTOP_APP=1
|
||||
|
||||
# Preserve system PATH for accessing system commands (e.g. imsg, brew)
|
||||
# Prepend packaged env/bin so packaged Python takes precedence
|
||||
export PATH="$ENV_DIR/bin:$PATH"
|
||||
|
||||
# Set SSL certificate paths for packaged environment
|
||||
# Query certifi path from the packaged Python interpreter
|
||||
if [ -x "$ENV_DIR/bin/python" ]; then
|
||||
CERT_FILE=$("$ENV_DIR/bin/python" -c \
|
||||
"import certifi; print(certifi.where())" 2>/dev/null)
|
||||
if [ -n "$CERT_FILE" ] && [ -f "$CERT_FILE" ]; then
|
||||
export SSL_CERT_FILE="$CERT_FILE"
|
||||
export REQUESTS_CA_BUNDLE="$CERT_FILE"
|
||||
export CURL_CA_BUNDLE="$CERT_FILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
cd "$HOME" || true
|
||||
|
||||
# Log level: env var QWENPAW_LOG_LEVEL or default to "info"
|
||||
LOG_LEVEL="${QWENPAW_LOG_LEVEL:-info}"
|
||||
|
||||
if [ ! -t 2 ]; then
|
||||
mkdir -p "$HOME/.qwenpaw"
|
||||
{ echo "=== $(date) QwenPaw starting ==="
|
||||
echo "ENV_DIR=$ENV_DIR"
|
||||
echo "Python: $ENV_DIR/bin/python (exists=$([ -x "$ENV_DIR/bin/python" ] && echo yes || echo no))"
|
||||
echo "PATH=$PATH"
|
||||
echo "LOG_LEVEL=$LOG_LEVEL"
|
||||
echo "SSL_CERT_FILE=${SSL_CERT_FILE:-not set}"
|
||||
if [ -n "$SSL_CERT_FILE" ] && [ -f "$SSL_CERT_FILE" ]; then
|
||||
echo "SSL certificate file found at $SSL_CERT_FILE"
|
||||
elif [ -n "$SSL_CERT_FILE" ]; then
|
||||
echo "WARNING: SSL_CERT_FILE set but file does not exist: $SSL_CERT_FILE"
|
||||
else
|
||||
echo "WARNING: SSL_CERT_FILE not set, SSL connections may fail"
|
||||
fi
|
||||
} >> "$LOG"
|
||||
exec 2>> "$LOG"
|
||||
exec 1>> "$LOG"
|
||||
if [ ! -x "$ENV_DIR/bin/python" ]; then
|
||||
echo "ERROR: python not executable at $ENV_DIR/bin/python"
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -f "$HOME/.qwenpaw/config.json" ]; then
|
||||
"$ENV_DIR/bin/python" -u -m qwenpaw init --defaults --accept-security
|
||||
fi
|
||||
echo "Launching python with log-level=$LOG_LEVEL..."
|
||||
"$ENV_DIR/bin/python" -u -m qwenpaw desktop --log-level "$LOG_LEVEL"
|
||||
EXIT=$?
|
||||
if [ $EXIT -ge 128 ]; then
|
||||
SIG=$((EXIT - 128))
|
||||
echo "Exit code: $EXIT (killed by signal $SIG, e.g. 9=SIGKILL 15=SIGTERM)"
|
||||
else
|
||||
echo "Exit code: $EXIT"
|
||||
fi
|
||||
echo "--- Full log: $LOG (scroll up for Python traceback if app exited early) ---"
|
||||
exit $EXIT
|
||||
fi
|
||||
if [ ! -f "$HOME/.qwenpaw/config.json" ]; then
|
||||
"$ENV_DIR/bin/python" -u -m qwenpaw init --defaults --accept-security
|
||||
fi
|
||||
exec "$ENV_DIR/bin/python" -u -m qwenpaw desktop --log-level "$LOG_LEVEL"
|
||||
LAUNCHER
|
||||
chmod +x "${APP_DIR}/Contents/MacOS/${APP_NAME}"
|
||||
|
||||
# Icon: use pre-generated icon.icns
|
||||
if [[ -f "${PACK_DIR}/assets/icon.icns" ]]; then
|
||||
echo "== Using pre-generated icon.icns =="
|
||||
else
|
||||
echo "Warning: icon.icns not found at ${PACK_DIR}/assets/icon.icns"
|
||||
echo "Generate it first: bash scripts/pack/generate_icons.sh"
|
||||
fi
|
||||
|
||||
# Info.plist (include icon key if icon.icns exists)
|
||||
# Prioritize version from __version__.py to ensure accuracy
|
||||
VERSION="${CURRENT_VERSION}"
|
||||
if [[ -z "${VERSION}" ]]; then
|
||||
# Fallback: try to get version from packed env metadata
|
||||
VERSION="$("${APP_DIR}/Contents/Resources/env/bin/python" -c \
|
||||
"from importlib.metadata import version; print(version('qwenpaw'))" 2>/dev/null \
|
||||
|| echo "0.0.0")"
|
||||
echo "Using version from packed env metadata: ${VERSION}"
|
||||
else
|
||||
echo "Version determined from __version__.py: ${VERSION}"
|
||||
fi
|
||||
ICON_PLIST=""
|
||||
if [[ -f "${PACK_DIR}/assets/icon.icns" ]]; then
|
||||
cp "${PACK_DIR}/assets/icon.icns" "${APP_DIR}/Contents/Resources/"
|
||||
ICON_PLIST="<key>CFBundleIconFile</key><string>icon.icns</string>
|
||||
"
|
||||
fi
|
||||
cat > "${APP_DIR}/Contents/Info.plist" << INFOPLIST
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" \
|
||||
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleExecutable</key><string>${APP_NAME}</string>
|
||||
<key>CFBundleIdentifier</key><string>com.qwenpaw.desktop</string>
|
||||
<key>CFBundleName</key><string>${APP_NAME}</string>
|
||||
<key>CFBundleVersion</key><string>${VERSION}</string>
|
||||
<key>CFBundleShortVersionString</key><string>${VERSION}</string>
|
||||
${ICON_PLIST}<key>NSHighResolutionCapable</key><true/>
|
||||
<key>LSMinimumSystemVersion</key><string>14.0</string>
|
||||
<key>NSDesktopFolderUsageDescription</key><string>QwenPaw may access files in your Desktop folder if you use file-related features. You can choose Don'\''t Allow; the app will still run with limited file access.</string>
|
||||
</dict>
|
||||
</plist>
|
||||
INFOPLIST
|
||||
|
||||
echo "== Built ${APP_DIR} =="
|
||||
# Optional: create zip for distribution (set CREATE_ZIP=1)
|
||||
if [[ -n "${CREATE_ZIP}" ]]; then
|
||||
ZIP_NAME="${DIST}/QwenPaw-${VERSION}-macOS.zip"
|
||||
ditto -c -k --sequesterRsrc --keepParent "${APP_DIR}" "${ZIP_NAME}"
|
||||
echo "== Created ${ZIP_NAME} =="
|
||||
fi
|
||||
@@ -0,0 +1,394 @@
|
||||
# One-click build: console -> conda-pack -> NSIS .exe. Run from repo root.
|
||||
# Requires: conda, node/npm (for console), NSIS (makensis) on PATH.
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$RepoRoot = (Get-Item $PSScriptRoot).Parent.Parent.FullName
|
||||
Set-Location $RepoRoot
|
||||
Write-Host "[build_win] REPO_ROOT=$RepoRoot"
|
||||
$PackDir = $PSScriptRoot
|
||||
$Dist = if ($env:DIST) { $env:DIST } else { "dist" }
|
||||
$Archive = Join-Path $Dist "qwenpaw-env.zip"
|
||||
$Unpacked = Join-Path $Dist "win-unpacked"
|
||||
$NsiPath = Join-Path $PackDir "desktop.nsi"
|
||||
|
||||
# Packages affected by conda-unpack bug on Windows (conda-pack Issue #154)
|
||||
# conda-unpack corrupts Python string escaping when replacing path prefixes.
|
||||
# Example: "\\\\?\\" (correct) -> "\\" (SyntaxError)
|
||||
# Solution: Reinstall these packages after conda-unpack to restore correct files.
|
||||
# See: issue.md, scripts/pack/WINDOWS_FIX.md
|
||||
$CondaUnpackAffectedPackages = @(
|
||||
"huggingface_hub" # Uses Windows extended-length path prefix (\\?\)
|
||||
"discord.py" # ARG_NAME_SUBREGEX contains \\?\* which gets corrupted
|
||||
)
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $Dist | Out-Null
|
||||
|
||||
Write-Host "== Building wheel (includes console frontend) =="
|
||||
# Skip wheel_build if dist already has a wheel for current version
|
||||
$VersionFile = Join-Path $RepoRoot "src\qwenpaw\__version__.py"
|
||||
$CurrentVersion = ""
|
||||
if (Test-Path $VersionFile) {
|
||||
$m = (Get-Content $VersionFile -Raw) -match '__version__\s*=\s*"([^"]+)"'
|
||||
if ($m) { $CurrentVersion = $Matches[1] }
|
||||
}
|
||||
$RunWheelBuild = $true
|
||||
if ($CurrentVersion) {
|
||||
$wheelGlob = Join-Path $Dist "qwenpaw-$CurrentVersion-*.whl"
|
||||
$existingWheels = Get-ChildItem -Path $wheelGlob -ErrorAction SilentlyContinue
|
||||
if ($existingWheels.Count -gt 0) {
|
||||
Write-Host "dist/ already has wheel for version $CurrentVersion, skipping."
|
||||
$RunWheelBuild = $false
|
||||
} else {
|
||||
# Clean up old wheels to avoid confusion
|
||||
$oldWheels = Get-ChildItem -Path (Join-Path $Dist "qwenpaw-*.whl") -ErrorAction SilentlyContinue
|
||||
if ($oldWheels.Count -gt 0) {
|
||||
Write-Host "Removing old wheel files: $($oldWheels | ForEach-Object { $_.Name })"
|
||||
$oldWheels | Remove-Item -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($RunWheelBuild) {
|
||||
$WheelBuildScript = Join-Path $RepoRoot "scripts\wheel_build.ps1"
|
||||
if (-not (Test-Path $WheelBuildScript)) {
|
||||
throw "wheel_build.ps1 not found: $WheelBuildScript"
|
||||
}
|
||||
& $WheelBuildScript
|
||||
if ($LASTEXITCODE -ne 0) { throw "wheel_build.ps1 failed with exit code $LASTEXITCODE" }
|
||||
}
|
||||
|
||||
Write-Host "== Building conda-packed env =="
|
||||
& python $PackDir\build_common.py --output $Archive --format zip --cache-wheels
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "build_common.py failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
if (-not (Test-Path $Archive)) {
|
||||
throw "Archive not created: $Archive"
|
||||
}
|
||||
|
||||
Write-Host "== Unpacking env =="
|
||||
if (Test-Path $Unpacked) { Remove-Item -Recurse -Force $Unpacked }
|
||||
Expand-Archive -Path $Archive -DestinationPath $Unpacked -Force
|
||||
$unpackedRoot = Get-ChildItem -Path $Unpacked -ErrorAction SilentlyContinue | Measure-Object
|
||||
Write-Host "[build_win] Unpacked entries in $Unpacked : $($unpackedRoot.Count)"
|
||||
|
||||
# Resolve env root: conda-pack usually puts python.exe at archive root; allow one nested dir.
|
||||
$EnvRoot = $Unpacked
|
||||
if (-not (Test-Path (Join-Path $EnvRoot "python.exe"))) {
|
||||
$found = Get-ChildItem -Path $Unpacked -Directory -ErrorAction SilentlyContinue |
|
||||
Where-Object { Test-Path (Join-Path $_.FullName "python.exe") } |
|
||||
Select-Object -First 1
|
||||
if ($found) { $EnvRoot = $found.FullName; Write-Host "[build_win] Env root: $EnvRoot" }
|
||||
}
|
||||
if (-not (Test-Path (Join-Path $EnvRoot "python.exe"))) {
|
||||
throw "python.exe not found in unpacked env (checked $Unpacked and one level down)."
|
||||
}
|
||||
if (-not [System.IO.Path]::IsPathRooted($EnvRoot)) {
|
||||
$EnvRoot = Join-Path $RepoRoot $EnvRoot
|
||||
}
|
||||
Write-Host "[build_win] python.exe found at env root: $EnvRoot"
|
||||
|
||||
# Rewrite prefix in packed env so paths point to current location (required after move).
|
||||
$CondaUnpack = Join-Path $EnvRoot "Scripts\conda-unpack.exe"
|
||||
if (Test-Path $CondaUnpack) {
|
||||
Write-Host "[build_win] Running conda-unpack..."
|
||||
& $CondaUnpack
|
||||
if ($LASTEXITCODE -ne 0) { throw "conda-unpack failed with exit code $LASTEXITCODE" }
|
||||
|
||||
# Fix conda-unpack bug: it corrupts Python string escaping on Windows
|
||||
# See: issue.md and https://github.com/conda/conda-pack/issues/154
|
||||
# Solution: Reinstall affected packages using cached wheels
|
||||
Write-Host "[build_win] Fixing conda-unpack corruption by reinstalling affected packages..."
|
||||
$WheelsCache = Join-Path $RepoRoot ".cache\conda_unpack_wheels"
|
||||
if (Test-Path $WheelsCache) {
|
||||
$pythonExe = Join-Path $EnvRoot "python.exe"
|
||||
|
||||
foreach ($pkg in $CondaUnpackAffectedPackages) {
|
||||
Write-Host " Reinstalling $pkg..."
|
||||
& $pythonExe -m pip install --force-reinstall --no-deps `
|
||||
--find-links $WheelsCache --no-index $pkg
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host " WARN: Failed to reinstall $pkg (exit code: $LASTEXITCODE)" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
|
||||
# Verify the fix worked
|
||||
Write-Host "[build_win] Verifying fix..."
|
||||
|
||||
# Create a verification script that handles SSL certificate store issues on Windows
|
||||
$verifyScript = @"
|
||||
import sys
|
||||
import ssl
|
||||
import os
|
||||
|
||||
# Set SSL certificate paths before importing anything that uses SSL
|
||||
try:
|
||||
import certifi
|
||||
cert_path = certifi.where()
|
||||
os.environ['SSL_CERT_FILE'] = cert_path
|
||||
os.environ['REQUESTS_CA_BUNDLE'] = cert_path
|
||||
os.environ['CURL_CA_BUNDLE'] = cert_path
|
||||
except ImportError:
|
||||
print("WARNING: certifi not available, using system certificates")
|
||||
|
||||
# Monkey-patch ssl.SSLContext.load_default_certs to handle Windows certificate store issues
|
||||
# This prevents SSL errors when the Windows certificate store contains corrupted certificates
|
||||
_original_load_default_certs = ssl.SSLContext.load_default_certs
|
||||
|
||||
def _safe_load_default_certs(self, purpose=ssl.Purpose.SERVER_AUTH):
|
||||
try:
|
||||
# Try loading from Windows certificate store first
|
||||
_original_load_default_certs(self, purpose)
|
||||
except ssl.SSLError as e:
|
||||
# If Windows store fails, fall back to certifi CA bundle
|
||||
print(f"WARNING: Windows certificate store load failed ({e}), using certifi CA bundle")
|
||||
try:
|
||||
import certifi
|
||||
self.load_verify_locations(cafile=certifi.where())
|
||||
except Exception as cert_err:
|
||||
print(f"ERROR: Failed to load certifi CA bundle: {cert_err}")
|
||||
raise
|
||||
|
||||
ssl.SSLContext.load_default_certs = _safe_load_default_certs
|
||||
|
||||
# Now verify imports
|
||||
try:
|
||||
from huggingface_hub import file_download
|
||||
print('✓ huggingface_hub import OK')
|
||||
except Exception as e:
|
||||
print(f'✗ huggingface_hub import failed: {e}')
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
import discord
|
||||
print('✓ discord.py import OK')
|
||||
except Exception as e:
|
||||
print(f'✗ discord.py import failed: {e}')
|
||||
sys.exit(1)
|
||||
"@
|
||||
|
||||
$verifyScriptPath = Join-Path $EnvRoot "verify_imports.py"
|
||||
Set-Content -Path $verifyScriptPath -Value $verifyScript -Encoding UTF8
|
||||
|
||||
$pythonExe = Join-Path $EnvRoot "python.exe"
|
||||
& $pythonExe $verifyScriptPath
|
||||
$verifyExitCode = $LASTEXITCODE
|
||||
|
||||
# Clean up verification script
|
||||
Remove-Item -Path $verifyScriptPath -Force -ErrorAction SilentlyContinue
|
||||
|
||||
if ($verifyExitCode -ne 0) {
|
||||
throw "CRITICAL: Package verification failed after reinstall. See output above for details."
|
||||
}
|
||||
Write-Host "[build_win] ✓ conda-unpack corruption fixed successfully."
|
||||
} else {
|
||||
Write-Host "[build_win] WARN: wheels_cache not found at $WheelsCache" -ForegroundColor Yellow
|
||||
Write-Host "[build_win] WARN: Cannot fix conda-unpack corruption. App may fail to start." -ForegroundColor Yellow
|
||||
}
|
||||
} else {
|
||||
Write-Host "[build_win] WARN: conda-unpack.exe not found at $CondaUnpack, skipping."
|
||||
}
|
||||
|
||||
Write-Host "== Pre-compiling Python bytecode for faster startup =="
|
||||
$pythonExe = Join-Path $EnvRoot "python.exe"
|
||||
if (Test-Path $pythonExe) {
|
||||
Write-Host "[build_win] Compiling all .py files to .pyc..."
|
||||
$compileStart = Get-Date
|
||||
|
||||
# Compile all Python files to bytecode
|
||||
# -q: quiet mode (only show errors)
|
||||
# -j 0: use all CPU cores for parallel compilation
|
||||
& $pythonExe -m compileall -q -j 0 $EnvRoot
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
$compileEnd = Get-Date
|
||||
$compileTime = ($compileEnd - $compileStart).TotalSeconds
|
||||
Write-Host "[build_win] ✓ Bytecode compilation completed in $($compileTime.ToString('F1')) seconds"
|
||||
|
||||
# Count compiled files for reporting
|
||||
$pycCount = (Get-ChildItem -Path $EnvRoot -Recurse -Filter "*.pyc" -ErrorAction SilentlyContinue | Measure-Object).Count
|
||||
Write-Host "[build_win] Generated $pycCount .pyc files (these will be included in installer)"
|
||||
} else {
|
||||
Write-Host "[build_win] WARN: Bytecode compilation had some errors (exit code: $LASTEXITCODE)" -ForegroundColor Yellow
|
||||
Write-Host "[build_win] This is usually not critical - app will compile on first run" -ForegroundColor Yellow
|
||||
}
|
||||
} else {
|
||||
Write-Host "[build_win] WARN: python.exe not found at $pythonExe, skipping bytecode compilation" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Main launcher .bat (will be hidden by VBS)
|
||||
$LauncherBat = Join-Path $EnvRoot "QwenPaw Desktop.bat"
|
||||
@"
|
||||
@echo off
|
||||
cd /d "%~dp0"
|
||||
|
||||
REM Isolate packaged Python from user site-packages to prevent conflicts
|
||||
set "PYTHONNOUSERSITE=1"
|
||||
|
||||
REM Preserve system PATH for accessing system commands
|
||||
REM Prepend packaged env to PATH so packaged Python takes precedence
|
||||
set "PATH=%~dp0;%~dp0Scripts;%PATH%"
|
||||
|
||||
REM Log level: env var QWENPAW_LOG_LEVEL or default to "info"
|
||||
if not defined QWENPAW_LOG_LEVEL set "QWENPAW_LOG_LEVEL=info"
|
||||
|
||||
REM Set SSL certificate paths for packaged environment
|
||||
REM Use temp file to avoid for /f blocking issue in bat scripts
|
||||
set "CERT_TMP=%TEMP%\qwenpaw_cert_%RANDOM%.txt"
|
||||
"%~dp0python.exe" -u -c "import certifi; print(certifi.where())" > "%CERT_TMP%" 2>nul
|
||||
set /p CERT_FILE=<"%CERT_TMP%"
|
||||
del "%CERT_TMP%" 2>nul
|
||||
if defined CERT_FILE (
|
||||
if exist "%CERT_FILE%" (
|
||||
set "SSL_CERT_FILE=%CERT_FILE%"
|
||||
set "REQUESTS_CA_BUNDLE=%CERT_FILE%"
|
||||
set "CURL_CA_BUNDLE=%CERT_FILE%"
|
||||
)
|
||||
)
|
||||
|
||||
if not exist "%USERPROFILE%\.qwenpaw\config.json" (
|
||||
"%~dp0python.exe" -u -m qwenpaw init --defaults --accept-security
|
||||
)
|
||||
"%~dp0python.exe" -u -m qwenpaw desktop --log-level %QWENPAW_LOG_LEVEL%
|
||||
"@ | Set-Content -Path $LauncherBat -Encoding ASCII
|
||||
|
||||
# Debug launcher .bat (shows console)
|
||||
$DebugBat = Join-Path $EnvRoot "QwenPaw Desktop (Debug).bat"
|
||||
@"
|
||||
@echo off
|
||||
cd /d "%~dp0"
|
||||
|
||||
REM Isolate packaged Python from user site-packages to prevent conflicts
|
||||
set "PYTHONNOUSERSITE=1"
|
||||
|
||||
REM Preserve system PATH for accessing system commands
|
||||
REM Prepend packaged env to PATH so packaged Python takes precedence
|
||||
set "PATH=%~dp0;%~dp0Scripts;%PATH%"
|
||||
|
||||
REM Debug mode: use debug log level by default (can override with QWENPAW_LOG_LEVEL)
|
||||
if not defined QWENPAW_LOG_LEVEL set "QWENPAW_LOG_LEVEL=debug"
|
||||
|
||||
REM Set SSL certificate paths for packaged environment
|
||||
REM Use temp file to avoid for /f blocking issue in bat scripts
|
||||
set "CERT_TMP=%TEMP%\qwenpaw_cert_%RANDOM%.txt"
|
||||
"%~dp0python.exe" -u -c "import certifi; print(certifi.where())" > "%CERT_TMP%" 2>nul
|
||||
set /p CERT_FILE=<"%CERT_TMP%"
|
||||
del "%CERT_TMP%" 2>nul
|
||||
if defined CERT_FILE (
|
||||
if exist "%CERT_FILE%" (
|
||||
set "SSL_CERT_FILE=%CERT_FILE%"
|
||||
set "REQUESTS_CA_BUNDLE=%CERT_FILE%"
|
||||
set "CURL_CA_BUNDLE=%CERT_FILE%"
|
||||
)
|
||||
)
|
||||
|
||||
echo ====================================
|
||||
echo QwenPaw Desktop - Debug Mode
|
||||
echo ====================================
|
||||
echo Working Directory: %cd%
|
||||
echo Python: "%~dp0python.exe"
|
||||
echo PATH: %PATH%
|
||||
echo PYTHONNOUSERSITE: %PYTHONNOUSERSITE%
|
||||
echo Log Level: %QWENPAW_LOG_LEVEL%
|
||||
echo SSL_CERT_FILE: %SSL_CERT_FILE%
|
||||
echo REQUESTS_CA_BUNDLE: %REQUESTS_CA_BUNDLE%
|
||||
echo CURL_CA_BUNDLE: %CURL_CA_BUNDLE%
|
||||
echo.
|
||||
if not exist "%USERPROFILE%\.qwenpaw\config.json" (
|
||||
echo [Init] Creating config...
|
||||
"%~dp0python.exe" -u -m qwenpaw init --defaults --accept-security
|
||||
)
|
||||
echo [Launch] Starting QwenPaw Desktop with log-level=%QWENPAW_LOG_LEVEL%...
|
||||
echo Press Ctrl+C to stop
|
||||
echo.
|
||||
"%~dp0python.exe" -u -m qwenpaw desktop --log-level %QWENPAW_LOG_LEVEL%
|
||||
echo.
|
||||
echo [Exit] QwenPaw Desktop closed
|
||||
pause
|
||||
"@ | Set-Content -Path $DebugBat -Encoding ASCII
|
||||
|
||||
# VBScript launcher (no console window)
|
||||
$LauncherVbs = Join-Path $EnvRoot "QwenPaw Desktop.vbs"
|
||||
@"
|
||||
Set WshShell = CreateObject("WScript.Shell")
|
||||
batPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\QwenPaw Desktop.bat"
|
||||
WshShell.Run Chr(34) & batPath & Chr(34), 0, False
|
||||
Set WshShell = Nothing
|
||||
"@ | Set-Content -Path $LauncherVbs -Encoding ASCII
|
||||
|
||||
# Create qwenpaw.cmd wrapper in env root so "qwenpaw" resolves to this
|
||||
# instead of Scripts\qwenpaw.exe whose embedded Python path may be stale
|
||||
# after conda-pack/unpack.
|
||||
$QwenpawCmd = Join-Path $EnvRoot "qwenpaw.cmd"
|
||||
@"
|
||||
@"%~dp0python.exe" -u -m qwenpaw %*
|
||||
"@ | Set-Content -Path $QwenpawCmd -Encoding ASCII
|
||||
|
||||
# Copy icon.ico to env root so NSIS can find it
|
||||
$IconSrc = Join-Path $PackDir "assets\icon.ico"
|
||||
if (Test-Path $IconSrc) {
|
||||
Copy-Item $IconSrc -Destination $EnvRoot -Force
|
||||
Write-Host "[build_win] Copied icon.ico to env root"
|
||||
} else {
|
||||
Write-Host "[build_win] WARN: icon.ico not found at $IconSrc"
|
||||
}
|
||||
|
||||
Write-Host "== Building NSIS installer =="
|
||||
|
||||
# Debug: Print EnvRoot directory contents
|
||||
Write-Host "=== EnvRoot=$EnvRoot ==="
|
||||
Write-Host "=== EnvRoot top files ==="
|
||||
Get-ChildItem -LiteralPath $EnvRoot -Force | Select-Object -First 50 | ForEach-Object { Write-Host $_.FullName }
|
||||
|
||||
# Prioritize version from __version__.py to ensure accuracy
|
||||
$Version = $CurrentVersion
|
||||
if (-not $Version) {
|
||||
# Fallback: try to get version from packed env metadata
|
||||
try {
|
||||
$Version = (& (Join-Path $EnvRoot "python.exe") -c "from importlib.metadata import version; print(version('qwenpaw'))" 2>&1) -replace '\s+$', ''
|
||||
Write-Host "[build_win] Using version from packed env metadata: $Version"
|
||||
} catch {
|
||||
Write-Host "[build_win] version from packed env failed: $_"
|
||||
}
|
||||
}
|
||||
if (-not $Version) { $Version = "0.0.0"; Write-Host "[build_win] WARN: Using fallback version 0.0.0" }
|
||||
Write-Host "[build_win] Version determined: $Version"
|
||||
Write-Host "[build_win] QWENPAW_VERSION=$Version OUTPUT_EXE will be under $Dist"
|
||||
$OutInstaller = Join-Path (Join-Path $RepoRoot $Dist) "QwenPaw-Setup-$Version.exe"
|
||||
# Pass absolute paths to NSIS (keep backslashes).
|
||||
$UnpackedFull = (Resolve-Path $EnvRoot).Path
|
||||
$OutputExeNsi = [System.IO.Path]::GetFullPath($OutInstaller)
|
||||
$nsiArgs = @(
|
||||
"/DQWENPAW_VERSION=$Version",
|
||||
"/DOUTPUT_EXE=$OutputExeNsi",
|
||||
"/DUNPACKED=$UnpackedFull",
|
||||
$NsiPath
|
||||
)
|
||||
|
||||
# Debug: Check if makensis is available
|
||||
Write-Host "=== Checking makensis availability ==="
|
||||
try {
|
||||
$makensisPath = (Get-Command makensis -ErrorAction Stop).Source
|
||||
Write-Host "[build_win] makensis found at: $makensisPath"
|
||||
} catch {
|
||||
throw "makensis not found in PATH. Please install NSIS and ensure makensis.exe is in PATH."
|
||||
}
|
||||
|
||||
Write-Host "[build_win] Running: makensis $($nsiArgs -join ' ')"
|
||||
Write-Host "=== NSIS will compile from: $NsiPath ==="
|
||||
Write-Host "=== NSIS unpacked source: $UnpackedFull ==="
|
||||
Write-Host "=== NSIS output installer: $OutputExeNsi ==="
|
||||
$nsisOutput = & makensis @nsiArgs 2>&1 | Out-String
|
||||
Write-Host "=== NSIS Output Begin ==="
|
||||
Write-Host $nsisOutput
|
||||
Write-Host "=== NSIS Output End ==="
|
||||
$makensisExit = $LASTEXITCODE
|
||||
Write-Host "[build_win] makensis exit code: $makensisExit"
|
||||
if ($makensisExit -ne 0) {
|
||||
Write-Host "ERROR: makensis compilation failed!"
|
||||
Write-Host "Check the NSIS output above for specific errors."
|
||||
throw "makensis failed with exit code $makensisExit"
|
||||
}
|
||||
if (-not (Test-Path $OutInstaller)) {
|
||||
throw "NSIS did not create installer: $OutInstaller"
|
||||
}
|
||||
Write-Host "== Built $OutInstaller =="
|
||||
@@ -0,0 +1,56 @@
|
||||
; QwenPaw Desktop NSIS installer. Run makensis from repo root after
|
||||
; building dist/win-unpacked (see scripts/pack/build_win.ps1).
|
||||
; Usage: makensis /DQWENPAW_VERSION=1.2.3 /DOUTPUT_EXE=dist\QwenPaw-Setup-1.2.3.exe scripts\pack\desktop.nsi
|
||||
|
||||
!include "MUI2.nsh"
|
||||
!define MUI_ABORTWARNING
|
||||
; Use custom icon from unpacked env (copied by build_win.ps1)
|
||||
!define MUI_ICON "${UNPACKED}\icon.ico"
|
||||
!define MUI_UNICON "${UNPACKED}\icon.ico"
|
||||
|
||||
!ifndef QWENPAW_VERSION
|
||||
!define QWENPAW_VERSION "0.0.0"
|
||||
!endif
|
||||
!ifndef OUTPUT_EXE
|
||||
!define OUTPUT_EXE "dist\QwenPaw-Setup-${QWENPAW_VERSION}.exe"
|
||||
!endif
|
||||
|
||||
Name "QwenPaw Desktop"
|
||||
OutFile "${OUTPUT_EXE}"
|
||||
InstallDir "$LOCALAPPDATA\QwenPaw"
|
||||
InstallDirRegKey HKCU "Software\QwenPaw" "InstallPath"
|
||||
RequestExecutionLevel user
|
||||
|
||||
!insertmacro MUI_PAGE_DIRECTORY
|
||||
!insertmacro MUI_PAGE_INSTFILES
|
||||
!insertmacro MUI_PAGE_FINISH
|
||||
!insertmacro MUI_UNPAGE_CONFIRM
|
||||
!insertmacro MUI_UNPAGE_INSTFILES
|
||||
!insertmacro MUI_LANGUAGE "SimpChinese"
|
||||
|
||||
; Pass /DUNPACKED=full_path from build_win.ps1 so path works when cwd != repo root
|
||||
!ifndef UNPACKED
|
||||
!define UNPACKED "dist\win-unpacked"
|
||||
!endif
|
||||
|
||||
Section "QwenPaw Desktop" SEC01
|
||||
SetOutPath "$INSTDIR"
|
||||
File /r "${UNPACKED}\*.*"
|
||||
WriteRegStr HKCU "Software\QwenPaw" "InstallPath" "$INSTDIR"
|
||||
WriteUninstaller "$INSTDIR\Uninstall.exe"
|
||||
|
||||
; Main shortcut - uses VBS to hide console window
|
||||
CreateShortcut "$SMPROGRAMS\QwenPaw Desktop.lnk" "$INSTDIR\QwenPaw Desktop.vbs" "" "$INSTDIR\icon.ico" 0
|
||||
CreateShortcut "$DESKTOP\QwenPaw Desktop.lnk" "$INSTDIR\QwenPaw Desktop.vbs" "" "$INSTDIR\icon.ico" 0
|
||||
|
||||
; Debug shortcut - shows console window for troubleshooting
|
||||
CreateShortcut "$SMPROGRAMS\QwenPaw Desktop (Debug).lnk" "$INSTDIR\QwenPaw Desktop (Debug).bat" "" "$INSTDIR\icon.ico" 0
|
||||
SectionEnd
|
||||
|
||||
Section "Uninstall"
|
||||
Delete "$SMPROGRAMS\QwenPaw Desktop.lnk"
|
||||
Delete "$SMPROGRAMS\QwenPaw Desktop (Debug).lnk"
|
||||
Delete "$DESKTOP\QwenPaw Desktop.lnk"
|
||||
RMDir /r "$INSTDIR"
|
||||
DeleteRegKey HKCU "Software\QwenPaw"
|
||||
SectionEnd
|
||||
@@ -0,0 +1,218 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Generate OSS metadata JSON files for release artifacts.
|
||||
|
||||
Usage:
|
||||
python generate_oss_metadata.py \
|
||||
--file dist/QwenPaw-Setup-1.0.0.exe \
|
||||
--product desktop \
|
||||
--platform win \
|
||||
--version 1.0.0 \
|
||||
--output metadata.json
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def calculate_sha256(filepath: str) -> str:
|
||||
"""Calculate SHA256 hash of a file."""
|
||||
sha256_hash = hashlib.sha256()
|
||||
with open(filepath, "rb") as f:
|
||||
for byte_block in iter(lambda: f.read(4096), b""):
|
||||
sha256_hash.update(byte_block)
|
||||
return sha256_hash.hexdigest()
|
||||
|
||||
|
||||
def format_file_size(size_bytes: int) -> str:
|
||||
"""Format file size to human-readable format."""
|
||||
for unit in ["B", "KB", "MB", "GB"]:
|
||||
if size_bytes < 1024.0:
|
||||
return f"{size_bytes:.1f} {unit}"
|
||||
size_bytes /= 1024.0
|
||||
return f"{size_bytes:.1f} TB"
|
||||
|
||||
|
||||
def get_file_type(filename: str) -> str:
|
||||
"""Extract file type from filename extension."""
|
||||
ext = Path(filename).suffix.lower()
|
||||
return ext[1:] if ext else "unknown"
|
||||
|
||||
|
||||
def generate_metadata(
|
||||
filepath: str,
|
||||
product: str,
|
||||
platform: str,
|
||||
version: str,
|
||||
) -> dict:
|
||||
"""Generate metadata for a single artifact file."""
|
||||
file_path = Path(filepath)
|
||||
if not file_path.exists():
|
||||
raise FileNotFoundError(f"File not found: {filepath}")
|
||||
|
||||
filename = file_path.name
|
||||
file_size = file_path.stat().st_size
|
||||
sha256 = calculate_sha256(filepath)
|
||||
file_type = get_file_type(filename)
|
||||
|
||||
file_id = f"{product}-{platform}-{version}"
|
||||
|
||||
platform_names = {
|
||||
"win-tauri": {
|
||||
"zh-CN": "Windows Tauri",
|
||||
"en-US": "for Windows (Tauri)",
|
||||
},
|
||||
"mac-tauri": {
|
||||
"zh-CN": "macOS Tauri",
|
||||
"en-US": "for macOS (Tauri)",
|
||||
},
|
||||
"win": {"zh-CN": "Windows 版", "en-US": "for Windows"},
|
||||
"mac": {"zh-CN": "macOS 版", "en-US": "for macOS"},
|
||||
"linux": {"zh-CN": "Linux 版", "en-US": "for Linux"},
|
||||
}
|
||||
|
||||
product_names = {
|
||||
"desktop": {"zh-CN": "桌面客户端", "en-US": "Desktop Client"},
|
||||
"cli": {"zh-CN": "命令行工具", "en-US": "CLI Tool"},
|
||||
}
|
||||
|
||||
platform_suffix = platform_names.get(
|
||||
platform, {"zh-CN": platform, "en-US": platform}
|
||||
)
|
||||
product_name = product_names.get(
|
||||
product, {"zh-CN": product, "en-US": product}
|
||||
)
|
||||
|
||||
oss_path = f"/files/apps/{product}/{platform}/{filename}"
|
||||
|
||||
metadata = {
|
||||
"id": file_id,
|
||||
"name": {
|
||||
"zh-CN": f"{product_name['zh-CN']} {platform_suffix['zh-CN']}",
|
||||
"en-US": f"{product_name['en-US']} {platform_suffix['en-US']}",
|
||||
},
|
||||
"description": {
|
||||
"zh-CN": f"适用于 {platform_suffix['zh-CN']}的{product_name['zh-CN']}安装包",
|
||||
"en-US": f"{product_name['en-US']} installer {platform_suffix['en-US']}",
|
||||
},
|
||||
"product": product,
|
||||
"platform": platform,
|
||||
"version": version,
|
||||
"filename": filename,
|
||||
"url": oss_path,
|
||||
"size": format_file_size(file_size),
|
||||
"size_bytes": file_size,
|
||||
"sha256": sha256,
|
||||
"updated_at": datetime.now(timezone.utc).isoformat(),
|
||||
"type": file_type,
|
||||
}
|
||||
|
||||
return metadata
|
||||
|
||||
|
||||
def merge_desktop_index(
|
||||
existing_index_path: str,
|
||||
new_metadata: dict,
|
||||
platform: str,
|
||||
) -> dict:
|
||||
"""Merge new metadata into desktop/index.json."""
|
||||
if os.path.exists(existing_index_path):
|
||||
with open(existing_index_path, "r", encoding="utf-8") as f:
|
||||
index = json.load(f)
|
||||
else:
|
||||
index = {
|
||||
"product": "desktop",
|
||||
"updated_at": datetime.now(timezone.utc).isoformat(),
|
||||
"platforms": {},
|
||||
"files": {},
|
||||
}
|
||||
|
||||
if "platforms" not in index:
|
||||
index["platforms"] = {}
|
||||
if "files" not in index:
|
||||
index["files"] = {}
|
||||
if "product" not in index:
|
||||
index["product"] = "desktop"
|
||||
|
||||
index["updated_at"] = datetime.now(timezone.utc).isoformat()
|
||||
|
||||
if platform not in index["platforms"]:
|
||||
index["platforms"][platform] = {"latest": "", "versions": []}
|
||||
|
||||
file_id = new_metadata["id"]
|
||||
index["platforms"][platform]["latest"] = file_id
|
||||
|
||||
if file_id not in index["platforms"][platform]["versions"]:
|
||||
index["platforms"][platform]["versions"].insert(0, file_id)
|
||||
|
||||
index["files"][file_id] = new_metadata
|
||||
|
||||
return index
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Generate OSS metadata for release artifacts"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--file", required=True, help="Path to the artifact file"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--product", required=True, help="Product name (e.g., desktop, cli)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--platform",
|
||||
required=True,
|
||||
help="Platform name (e.g., win, mac, linux)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--version", required=True, help="Version string (e.g., 1.0.0)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
default="metadata.json",
|
||||
help="Output metadata JSON file path",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--merge-index",
|
||||
help="Path to existing desktop/index.json to merge into",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output-index",
|
||||
help="Output path for merged desktop/index.json",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
print(f"Generating metadata for: {args.file}")
|
||||
metadata = generate_metadata(
|
||||
args.file, args.product, args.platform, args.version
|
||||
)
|
||||
|
||||
with open(args.output, "w", encoding="utf-8") as f:
|
||||
json.dump(metadata, f, indent=2, ensure_ascii=False)
|
||||
print(f"✓ Metadata written to: {args.output}")
|
||||
print(f" ID: {metadata['id']}")
|
||||
print(f" Size: {metadata['size']}")
|
||||
print(f" SHA256: {metadata['sha256'][:16]}...")
|
||||
|
||||
# Merge into desktop/index.json if requested
|
||||
if args.merge_index and args.output_index:
|
||||
print(f"\nMerging into desktop index: {args.merge_index}")
|
||||
merged_index = merge_desktop_index(
|
||||
args.merge_index, metadata, args.platform
|
||||
)
|
||||
with open(args.output_index, "w", encoding="utf-8") as f:
|
||||
json.dump(merged_index, f, indent=2, ensure_ascii=False)
|
||||
print(f"✓ Desktop index written to: {args.output_index}")
|
||||
print(
|
||||
f" Latest {args.platform}: {merged_index['platforms'][args.platform]['latest']}"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,649 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Scan local plugins, build distributable zips, and emit OSS metadata.
|
||||
|
||||
Mirrors the shape of ``generate_oss_metadata.py`` so the resulting
|
||||
``metadata/plugins/index.json`` is a drop-in product entry for the existing
|
||||
Downloads page (it iterates ``mainIndex.products`` regardless of product type).
|
||||
|
||||
Layout produced under ``--dist``::
|
||||
|
||||
dist/plugins/
|
||||
bundle/<plugin_id>/<id>-<version>.zip
|
||||
tool/<plugin_id>/<id>-<version>.zip
|
||||
index.json
|
||||
|
||||
Each plugin is stored under its own directory on the CDN
|
||||
(``/files/plugins/{kind}/{plugin_id}/…``), not flat under ``{kind}/``.
|
||||
|
||||
Each plugin source tree is full-rebuild zipped: this means deletions in the
|
||||
repo propagate through to OSS on the next run (no stale entries left behind).
|
||||
Rebuilding the same version overwrites the zip at a stable URL; bump the
|
||||
plugin version in ``plugin.json`` when you need a distinct release artifact.
|
||||
|
||||
A plugin can opt out of publishing by setting ``"publish": false`` in its
|
||||
``plugin.json``.
|
||||
|
||||
A plugin can trim dev-only files from its zip by declaring ``"pack_exclude"``
|
||||
in ``plugin.json``: a list of plugin-root-relative paths (exact file or
|
||||
directory pruned recursively). ``plugin.json`` and the declared ``entry``
|
||||
files are always packed. Packaging fails if a declared entry file is missing,
|
||||
so a frontend build cannot be silently omitted from a published zip. This
|
||||
script does not build plugin sources; release callers must rebuild app
|
||||
frontends before invoking it.
|
||||
|
||||
Declared ``entry`` files must exist on disk at pack time. A plugin whose
|
||||
build produces additional required artifacts (e.g. vendored static assets
|
||||
outside its own ``npm run build``) can declare ``"pack_requires"``: a list
|
||||
of plugin-root-relative files that must also exist. A missing entry or
|
||||
required file fails the pack for that plugin with an actionable error
|
||||
(``"pack_requires_hint"`` is printed verbatim when provided) and the run
|
||||
exits non-zero, so a broken artifact is never published silently.
|
||||
|
||||
Pass ``--only <plugin_id>`` (repeatable) to pack a subset of plugins, e.g.
|
||||
for a standalone release of a single plugin driven by its own version bump.
|
||||
Conversely, ``--exclude <plugin_id>`` (repeatable) skips plugins that are
|
||||
released through their own dedicated pipeline.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import fnmatch
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import zipfile
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
KIND_DIRS = ("bundle", "tool", "apps")
|
||||
|
||||
EXCLUDE_PATTERNS = (
|
||||
"__pycache__",
|
||||
"*.pyc",
|
||||
"*.pyo",
|
||||
".DS_Store",
|
||||
".git",
|
||||
".gitignore",
|
||||
"node_modules",
|
||||
".venv",
|
||||
"venv",
|
||||
".pytest_cache",
|
||||
".mypy_cache",
|
||||
".ruff_cache",
|
||||
"*.log",
|
||||
)
|
||||
|
||||
|
||||
def _is_excluded(name: str) -> bool:
|
||||
return any(fnmatch.fnmatch(name, pat) for pat in EXCLUDE_PATTERNS)
|
||||
|
||||
|
||||
def _normalize_pack_exclude(manifest: dict[str, Any]) -> list[str]:
|
||||
"""Return sanitized plugin-root-relative ``pack_exclude`` entries.
|
||||
|
||||
Unsafe entries (traversal, absolute, empty) are dropped with a warning.
|
||||
"""
|
||||
raw = manifest.get("pack_exclude")
|
||||
if raw is None:
|
||||
return []
|
||||
if not isinstance(raw, list):
|
||||
print(
|
||||
"WARNING: ignoring pack_exclude - expected a list of "
|
||||
f"relative paths, got {type(raw).__name__}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return []
|
||||
cleaned: list[str] = []
|
||||
for item in raw:
|
||||
text = str(item).strip().replace("\\", "/").strip("/")
|
||||
parts = [p for p in text.split("/") if p]
|
||||
if not parts or "." in parts or ".." in parts or ":" in parts[0]:
|
||||
print(
|
||||
f"WARNING: ignoring unsafe pack_exclude entry: {item!r}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
continue
|
||||
cleaned.append("/".join(parts))
|
||||
return cleaned
|
||||
|
||||
|
||||
def _protected_relpaths(manifest: dict[str, Any]) -> set[str]:
|
||||
"""Files that must always ship even when listed in ``pack_exclude``."""
|
||||
protected = {"plugin.json"}
|
||||
entry = manifest.get("entry")
|
||||
if isinstance(entry, dict):
|
||||
for value in entry.values():
|
||||
if isinstance(value, str) and value.strip():
|
||||
protected.add(value.strip().replace("\\", "/").strip("/"))
|
||||
return protected
|
||||
|
||||
|
||||
def _required_relpaths(manifest: dict[str, Any]) -> list[str]:
|
||||
"""Files that must exist on disk before the plugin may be packed.
|
||||
|
||||
Declared ``entry`` files are always required; ``pack_requires`` adds
|
||||
build artifacts the manifest cannot express as entries (e.g. vendored
|
||||
static assets referenced at runtime).
|
||||
"""
|
||||
required = sorted(_protected_relpaths(manifest) - {"plugin.json"})
|
||||
raw = manifest.get("pack_requires")
|
||||
if raw is None:
|
||||
return required
|
||||
if not isinstance(raw, list):
|
||||
print(
|
||||
"WARNING: ignoring pack_requires - expected a list of "
|
||||
f"relative paths, got {type(raw).__name__}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return required
|
||||
for item in raw:
|
||||
text = str(item).strip().replace("\\", "/").strip("/")
|
||||
parts = [p for p in text.split("/") if p]
|
||||
if not parts or "." in parts or ".." in parts or ":" in parts[0]:
|
||||
print(
|
||||
f"WARNING: ignoring unsafe pack_requires entry: {item!r}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
continue
|
||||
rel = "/".join(parts)
|
||||
if rel not in required:
|
||||
required.append(rel)
|
||||
return required
|
||||
|
||||
|
||||
def _missing_required_files(
|
||||
plugin_dir: Path,
|
||||
manifest: dict[str, Any],
|
||||
) -> list[str]:
|
||||
"""Return required files absent from the plugin tree, POSIX-relative."""
|
||||
return [
|
||||
rel
|
||||
for rel in _required_relpaths(manifest)
|
||||
if not (plugin_dir / rel).is_file()
|
||||
]
|
||||
|
||||
|
||||
def _report_missing_required(
|
||||
plugin_dir: Path,
|
||||
manifest: dict[str, Any],
|
||||
missing: list[str],
|
||||
) -> None:
|
||||
"""Print an actionable per-plugin validation failure."""
|
||||
print(
|
||||
f"ERROR: {plugin_dir.name}: refusing to pack - required "
|
||||
"file(s) missing:",
|
||||
file=sys.stderr,
|
||||
)
|
||||
for rel in missing:
|
||||
print(f" - {rel}", file=sys.stderr)
|
||||
hint = str(manifest.get("pack_requires_hint") or "").strip()
|
||||
if hint:
|
||||
print(f" hint: {hint}", file=sys.stderr)
|
||||
|
||||
|
||||
def _is_pack_excluded(
|
||||
rel_posix: str,
|
||||
pack_exclude: list[str],
|
||||
protected: set[str],
|
||||
) -> bool:
|
||||
"""True when *rel_posix* is covered by a ``pack_exclude`` entry."""
|
||||
if not pack_exclude or rel_posix in protected:
|
||||
return False
|
||||
return any(
|
||||
rel_posix == pat or rel_posix.startswith(pat + "/")
|
||||
for pat in pack_exclude
|
||||
)
|
||||
|
||||
|
||||
def _format_size(size_bytes: int) -> str:
|
||||
size = float(size_bytes)
|
||||
for unit in ("B", "KB", "MB", "GB"):
|
||||
if size < 1024.0:
|
||||
return f"{size:.1f} {unit}"
|
||||
size /= 1024.0
|
||||
return f"{size:.1f} TB"
|
||||
|
||||
|
||||
def _sha256_of_file(path: Path) -> str:
|
||||
h = hashlib.sha256()
|
||||
with path.open("rb") as f:
|
||||
for chunk in iter(lambda: f.read(65536), b""):
|
||||
h.update(chunk)
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
def _iter_tree_relpaths(
|
||||
plugin_dir: Path,
|
||||
manifest: dict[str, Any] | None = None,
|
||||
) -> list[str]:
|
||||
"""Return packable plugin-root-relative paths, always POSIX-separated.
|
||||
|
||||
Paths stay POSIX on every platform so zip entry names and ``pack_exclude``
|
||||
matching behave identically on Windows and on Unix.
|
||||
"""
|
||||
pack_exclude = _normalize_pack_exclude(manifest or {})
|
||||
protected = _protected_relpaths(manifest or {})
|
||||
rels: list[str] = []
|
||||
for root, dirs, files in os.walk(plugin_dir):
|
||||
dirs[:] = [d for d in dirs if not _is_excluded(d)]
|
||||
for fname in files:
|
||||
if _is_excluded(fname):
|
||||
continue
|
||||
rel = (Path(root) / fname).relative_to(plugin_dir).as_posix()
|
||||
if _is_pack_excluded(rel, pack_exclude, protected):
|
||||
continue
|
||||
rels.append(rel)
|
||||
rels.sort()
|
||||
return rels
|
||||
|
||||
|
||||
def _validate_declared_entries(
|
||||
plugin_dir: Path,
|
||||
manifest: dict[str, Any],
|
||||
) -> None:
|
||||
"""Fail closed when a manifest entry point is absent from the tree."""
|
||||
entry = manifest.get("entry")
|
||||
if not isinstance(entry, dict):
|
||||
return
|
||||
|
||||
missing: list[str] = []
|
||||
for value in entry.values():
|
||||
if not isinstance(value, str) or not value.strip():
|
||||
continue
|
||||
rel = value.strip().replace("\\", "/").strip("/")
|
||||
if not (plugin_dir / rel).is_file():
|
||||
missing.append(rel)
|
||||
|
||||
if missing:
|
||||
plugin_id = str(manifest.get("id") or plugin_dir.name)
|
||||
paths = ", ".join(sorted(missing))
|
||||
raise FileNotFoundError(
|
||||
f"cannot package {plugin_id}: declared entry file(s) missing: "
|
||||
f"{paths}",
|
||||
)
|
||||
|
||||
|
||||
def _zip_plugin(
|
||||
plugin_dir: Path,
|
||||
out_zip: Path,
|
||||
manifest: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
if manifest is not None:
|
||||
_validate_declared_entries(plugin_dir, manifest)
|
||||
out_zip.parent.mkdir(parents=True, exist_ok=True)
|
||||
with zipfile.ZipFile(out_zip, "w", zipfile.ZIP_DEFLATED) as zf:
|
||||
for rel in _iter_tree_relpaths(plugin_dir, manifest):
|
||||
zf.write(plugin_dir / rel, f"{plugin_dir.name}/{rel}")
|
||||
|
||||
|
||||
def _read_manifest(plugin_dir: Path) -> dict[str, Any] | None:
|
||||
manifest_path = plugin_dir / "plugin.json"
|
||||
if not manifest_path.is_file():
|
||||
return None
|
||||
try:
|
||||
with manifest_path.open("r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except (OSError, json.JSONDecodeError) as exc:
|
||||
print(
|
||||
f"WARNING: skipping {plugin_dir} - cannot read plugin.json: {exc}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
def _localized_field(value: Any) -> dict[str, str]:
|
||||
"""Normalize manifest name/description to ``{zh-CN, en-US}``.
|
||||
|
||||
Accepts a plain string (duplicated to both locales) or a mapping with
|
||||
``zh-CN`` / ``en-US`` (also accepts ``zh`` / ``en`` aliases).
|
||||
"""
|
||||
if isinstance(value, dict):
|
||||
zh = str(value.get("zh-CN") or value.get("zh") or "").strip()
|
||||
en = str(value.get("en-US") or value.get("en") or "").strip()
|
||||
fallback = zh or en
|
||||
return {
|
||||
"zh-CN": zh or en or fallback,
|
||||
"en-US": en or zh or fallback,
|
||||
}
|
||||
text = str(value or "").strip()
|
||||
return {"zh-CN": text, "en-US": text}
|
||||
|
||||
|
||||
def _localized_description(manifest: dict[str, Any]) -> dict[str, str]:
|
||||
"""CDN metadata description.
|
||||
Prefer ``description_i18n``, else ``description``.
|
||||
"""
|
||||
i18n = manifest.get("description_i18n")
|
||||
if i18n is not None:
|
||||
return _localized_field(i18n)
|
||||
return _localized_field(manifest.get("description") or "")
|
||||
|
||||
|
||||
def _normalize_ver(raw: str) -> str:
|
||||
"""Strip leading 'v' and surrounding whitespace from a version string."""
|
||||
s = raw.strip()
|
||||
if s.lower().startswith("v"):
|
||||
s = s[1:]
|
||||
return s
|
||||
|
||||
|
||||
def get_version(manifest: dict[str, Any]) -> dict[str, str] | None:
|
||||
"""Return a normalized ``qwenpaw_version`` for CDN metadata.
|
||||
|
||||
Strategy:
|
||||
1. If the manifest already provides the structured
|
||||
``qwenpaw_version`` field, return it directly — the plugin
|
||||
explicitly declares its compatibility.
|
||||
2. For legacy plugins that only declare ``min_version`` /
|
||||
``max_version``, synthesize a proper ``qwenpaw_version`` dict
|
||||
with ``min`` and/or ``max`` keys so downstream consumers
|
||||
(e.g. ``_is_entry_compatible``) always see a consistent
|
||||
structure.
|
||||
|
||||
Version strings are sanitized (leading 'v' and whitespace removed).
|
||||
Returns ``None`` when no version constraint is declared.
|
||||
"""
|
||||
# --- Case 1: structured field available, use directly ---
|
||||
qwenpaw_version = manifest.get("qwenpaw_version")
|
||||
if isinstance(qwenpaw_version, dict):
|
||||
return {
|
||||
k: _normalize_ver(str(v))
|
||||
for k, v in qwenpaw_version.items()
|
||||
if k in ("min", "max")
|
||||
}
|
||||
|
||||
# --- Case 2: legacy min/max, synthesize structured dict ---
|
||||
min_ver_str = _normalize_ver(str(manifest.get("min_version") or ""))
|
||||
max_ver_str = _normalize_ver(str(manifest.get("max_version") or ""))
|
||||
if not min_ver_str and not max_ver_str:
|
||||
return None
|
||||
|
||||
result: dict[str, str] = {}
|
||||
if min_ver_str:
|
||||
result["min"] = min_ver_str
|
||||
if max_ver_str:
|
||||
result["max"] = max_ver_str
|
||||
return result
|
||||
|
||||
|
||||
def _build_metadata(
|
||||
manifest: dict[str, Any],
|
||||
*,
|
||||
file_id: str,
|
||||
plugin_id: str,
|
||||
version: str,
|
||||
kind: str,
|
||||
zip_path: Path,
|
||||
cdn_path: str,
|
||||
) -> dict[str, Any]:
|
||||
size_bytes = zip_path.stat().st_size
|
||||
metadata: dict[str, Any] = {
|
||||
"id": file_id,
|
||||
"plugin_id": plugin_id,
|
||||
"name": _localized_field(manifest.get("name") or plugin_id),
|
||||
"description": _localized_description(manifest),
|
||||
"product": "plugins",
|
||||
"platform": kind,
|
||||
"version": version,
|
||||
"author": str(manifest.get("author") or ""),
|
||||
"filename": zip_path.name,
|
||||
"url": cdn_path,
|
||||
"size": _format_size(size_bytes),
|
||||
"size_bytes": size_bytes,
|
||||
"sha256": _sha256_of_file(zip_path),
|
||||
"updated_at": datetime.now(timezone.utc).isoformat(),
|
||||
"type": "zip",
|
||||
}
|
||||
|
||||
version_constraint = get_version(manifest)
|
||||
if version_constraint:
|
||||
metadata["qwenpaw_version"] = version_constraint
|
||||
|
||||
return metadata
|
||||
|
||||
|
||||
def _matches_only(
|
||||
only: list[str] | None,
|
||||
plugin_id: str,
|
||||
dir_name: str,
|
||||
) -> bool:
|
||||
"""True when *only* is unset or matches the plugin id / directory name."""
|
||||
if not only:
|
||||
return True
|
||||
return plugin_id in only or dir_name in only
|
||||
|
||||
|
||||
def _selected(
|
||||
only: list[str] | None,
|
||||
exclude: list[str] | None,
|
||||
plugin_id: str,
|
||||
dir_name: str,
|
||||
) -> bool:
|
||||
"""Apply ``--only`` / ``--exclude`` selection to a plugin."""
|
||||
if exclude and (plugin_id in exclude or dir_name in exclude):
|
||||
return False
|
||||
return _matches_only(only, plugin_id, dir_name)
|
||||
|
||||
|
||||
def discover_and_pack(
|
||||
plugins_root: Path,
|
||||
dist_root: Path,
|
||||
cdn_prefix: str,
|
||||
only: list[str] | None = None,
|
||||
exclude: list[str] | None = None,
|
||||
) -> tuple[dict[str, Any], list[str]]:
|
||||
"""Scan, validate, zip, and assemble the plugins index.
|
||||
|
||||
Always full-rebuild. Returns the index plus the ids of plugins that
|
||||
failed required-file validation and were not packed.
|
||||
"""
|
||||
index: dict[str, Any] = {
|
||||
"product": "plugins",
|
||||
"updated_at": datetime.now(timezone.utc).isoformat(),
|
||||
"platforms": {},
|
||||
"files": {},
|
||||
}
|
||||
failed: list[str] = []
|
||||
|
||||
if not plugins_root.is_dir():
|
||||
print(
|
||||
f"WARNING: plugins root does not exist: {plugins_root}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return index, failed
|
||||
|
||||
for kind in KIND_DIRS:
|
||||
kind_dir = plugins_root / kind
|
||||
if not kind_dir.is_dir():
|
||||
continue
|
||||
for plugin_dir in sorted(p for p in kind_dir.iterdir() if p.is_dir()):
|
||||
manifest = _read_manifest(plugin_dir)
|
||||
if manifest is None:
|
||||
continue
|
||||
if manifest.get("publish") is False:
|
||||
print(f" - skip {plugin_dir.name} (publish=false)")
|
||||
continue
|
||||
|
||||
plugin_id = str(manifest.get("id") or plugin_dir.name)
|
||||
if not _selected(only, exclude, plugin_id, plugin_dir.name):
|
||||
continue
|
||||
missing = _missing_required_files(plugin_dir, manifest)
|
||||
if missing:
|
||||
_report_missing_required(plugin_dir, manifest, missing)
|
||||
failed.append(plugin_id)
|
||||
continue
|
||||
version = str(manifest.get("version") or "0.0.0")
|
||||
zip_name = f"{plugin_id}-{version}.zip"
|
||||
zip_path = dist_root / kind / plugin_id / zip_name
|
||||
|
||||
print(
|
||||
f" + pack {kind}/{plugin_dir.name} -> "
|
||||
f"{plugin_id}/{zip_path.name}",
|
||||
)
|
||||
_zip_plugin(plugin_dir, zip_path, manifest)
|
||||
|
||||
cdn_path = (
|
||||
f"{cdn_prefix.rstrip('/')}/{kind}/{plugin_id}/{zip_name}"
|
||||
)
|
||||
file_id = f"{plugin_id}-{version}"
|
||||
metadata = _build_metadata(
|
||||
manifest,
|
||||
file_id=file_id,
|
||||
plugin_id=plugin_id,
|
||||
version=version,
|
||||
kind=kind,
|
||||
zip_path=zip_path,
|
||||
cdn_path=cdn_path,
|
||||
)
|
||||
index["files"][file_id] = metadata
|
||||
kind_entry = index["platforms"].setdefault(kind, {"versions": []})
|
||||
if file_id not in kind_entry["versions"]:
|
||||
kind_entry["versions"].insert(0, file_id)
|
||||
|
||||
return index, failed
|
||||
|
||||
|
||||
def _dry_run_scan(
|
||||
plugins_root: Path,
|
||||
only: list[str] | None,
|
||||
exclude: list[str] | None,
|
||||
) -> None:
|
||||
"""List what would be packed without writing anything."""
|
||||
for kind in KIND_DIRS:
|
||||
kind_dir = plugins_root / kind
|
||||
if not kind_dir.is_dir():
|
||||
continue
|
||||
for plugin_dir in sorted(p for p in kind_dir.iterdir() if p.is_dir()):
|
||||
manifest = _read_manifest(plugin_dir)
|
||||
if manifest is None:
|
||||
continue
|
||||
if manifest.get("publish") is False:
|
||||
print(f" - skip {plugin_dir.name} (publish=false)")
|
||||
continue
|
||||
plugin_id = str(manifest.get("id") or plugin_dir.name)
|
||||
if not _selected(only, exclude, plugin_id, plugin_dir.name):
|
||||
continue
|
||||
missing = _missing_required_files(plugin_dir, manifest)
|
||||
if missing:
|
||||
_report_missing_required(plugin_dir, manifest, missing)
|
||||
continue
|
||||
print(
|
||||
f" ~ would pack {kind}/{plugin_dir.name} "
|
||||
f"(id={manifest.get('id')}, "
|
||||
f"version={manifest.get('version')})"
|
||||
)
|
||||
print("Dry run complete.")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument(
|
||||
"--plugins-root",
|
||||
default="plugins",
|
||||
help="Path to the plugins/ directory (default: plugins)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dist",
|
||||
default="dist/plugins",
|
||||
help="Output directory for zip artifacts (default: dist/plugins)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--metadata-out",
|
||||
default=None,
|
||||
help=(
|
||||
"Where to write the assembled plugins index JSON. "
|
||||
"Defaults to <dist>/index.json."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--cdn-prefix",
|
||||
default="/files/plugins",
|
||||
help="OSS path prefix used in metadata URLs (default: /files/plugins)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--only",
|
||||
action="append",
|
||||
default=None,
|
||||
metavar="PLUGIN_ID",
|
||||
help=(
|
||||
"Pack only the plugin(s) whose manifest id or directory name "
|
||||
"matches. Repeatable. Default: pack all plugins."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--exclude",
|
||||
action="append",
|
||||
default=None,
|
||||
metavar="PLUGIN_ID",
|
||||
help=(
|
||||
"Skip the plugin(s) whose manifest id or directory name "
|
||||
"matches (e.g. plugins with a dedicated release pipeline). "
|
||||
"Repeatable."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dry-run",
|
||||
action="store_true",
|
||||
help="Scan + plan only; do not write zips or index.",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
plugins_root = Path(args.plugins_root).resolve()
|
||||
dist_root = Path(args.dist).resolve()
|
||||
metadata_out = Path(
|
||||
args.metadata_out
|
||||
if args.metadata_out is not None
|
||||
else dist_root / "index.json"
|
||||
).resolve()
|
||||
|
||||
print(f"Scanning plugins under: {plugins_root}")
|
||||
if args.dry_run:
|
||||
_dry_run_scan(plugins_root, args.only, args.exclude)
|
||||
return 0
|
||||
|
||||
if dist_root.exists():
|
||||
# Wipe stale zips/dirs so deletions propagate cleanly.
|
||||
for kind in KIND_DIRS:
|
||||
kind_root = dist_root / kind
|
||||
if not kind_root.is_dir():
|
||||
continue
|
||||
for child in kind_root.iterdir():
|
||||
if child.is_file():
|
||||
child.unlink()
|
||||
elif child.is_dir():
|
||||
shutil.rmtree(child)
|
||||
dist_root.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
index, failed = discover_and_pack(
|
||||
plugins_root,
|
||||
dist_root,
|
||||
args.cdn_prefix,
|
||||
only=args.only,
|
||||
exclude=args.exclude,
|
||||
)
|
||||
|
||||
metadata_out.parent.mkdir(parents=True, exist_ok=True)
|
||||
with metadata_out.open("w", encoding="utf-8") as f:
|
||||
json.dump(index, f, indent=2, ensure_ascii=False)
|
||||
|
||||
print()
|
||||
print(f"Wrote index: {metadata_out}")
|
||||
n_files = len(index["files"])
|
||||
n_kinds = len(index["platforms"])
|
||||
print(f" {n_files} plugin(s) across {n_kinds} kind(s)")
|
||||
if failed:
|
||||
print(
|
||||
"ERROR: required-file validation failed for: "
|
||||
+ ", ".join(sorted(failed)),
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Merge a newly built plugin index with a historical one from OSS.
|
||||
|
||||
Used by the ``plugins-release.yml`` workflow to preserve old plugin
|
||||
versions on the CDN while adding new ones.
|
||||
|
||||
Merge rules:
|
||||
- ``files``: keyed by file_id (``{plugin_id}-{version}``). New entries
|
||||
overwrite same-id old entries; different ids from old are preserved unless
|
||||
their plugin id is explicitly retired.
|
||||
- ``platforms.{kind}.versions``: union of new and old version lists,
|
||||
new versions first, old versions appended with deduplication. Versions that
|
||||
belong to a retired plugin id are omitted.
|
||||
|
||||
Usage::
|
||||
|
||||
python scripts/pack/merge_plugin_index.py \
|
||||
--new dist/plugins/index.json \
|
||||
--old existing-index.json \
|
||||
--out dist/plugins/index.json \
|
||||
--retire-plugin-id old-plugin-id
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def merge_indexes(
|
||||
new_index: dict,
|
||||
old_index: dict,
|
||||
retired_plugin_ids: set[str] | None = None,
|
||||
) -> dict:
|
||||
"""Merge *old_index* into *new_index* (mutates and returns *new_index*)."""
|
||||
retired_plugin_ids = retired_plugin_ids or set()
|
||||
|
||||
# files: same file_id is overwritten by new; different ids preserved.
|
||||
old_files = old_index.get("files", {})
|
||||
retired_file_ids = {
|
||||
file_id
|
||||
for file_id, metadata in old_files.items()
|
||||
if metadata.get("plugin_id") in retired_plugin_ids
|
||||
}
|
||||
old_files = {
|
||||
file_id: metadata
|
||||
for file_id, metadata in old_files.items()
|
||||
if file_id not in retired_file_ids
|
||||
}
|
||||
new_files = new_index.get("files", {})
|
||||
new_index["files"] = {**old_files, **new_files}
|
||||
|
||||
# platforms.versions: union, new first, old appended with dedup.
|
||||
old_platforms = old_index.get("platforms", {})
|
||||
all_kinds = set(
|
||||
list(new_index.get("platforms", {}).keys())
|
||||
+ list(old_platforms.keys()),
|
||||
)
|
||||
for kind in all_kinds:
|
||||
old_versions = old_platforms.get(kind, {}).get("versions", [])
|
||||
new_versions = (
|
||||
new_index.get("platforms", {}).get(kind, {}).get("versions", [])
|
||||
)
|
||||
seen = set(new_versions)
|
||||
merged = list(new_versions)
|
||||
for v in old_versions:
|
||||
if v not in seen and v not in retired_file_ids:
|
||||
merged.append(v)
|
||||
seen.add(v)
|
||||
new_index.setdefault("platforms", {})
|
||||
new_index["platforms"].setdefault(kind, {})
|
||||
new_index["platforms"][kind]["versions"] = merged
|
||||
|
||||
return new_index
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> None:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Merge new and historical plugin indexes.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--new",
|
||||
required=True,
|
||||
type=Path,
|
||||
help="Path to the newly generated index.json",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--old",
|
||||
required=True,
|
||||
type=Path,
|
||||
help="Path to the existing (historical) index.json",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--out",
|
||||
required=True,
|
||||
type=Path,
|
||||
help="Output path for the merged index.json",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--retire-plugin-id",
|
||||
action="append",
|
||||
default=[],
|
||||
help="Plugin id to remove from the historical index (repeatable)",
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
with open(args.new, encoding="utf-8") as f:
|
||||
new_index = json.load(f)
|
||||
with open(args.old, encoding="utf-8") as f:
|
||||
old_index = json.load(f)
|
||||
|
||||
merged = merge_indexes(
|
||||
new_index,
|
||||
old_index,
|
||||
set(args.retire_plugin_id),
|
||||
)
|
||||
|
||||
with open(args.out, "w", encoding="utf-8") as f:
|
||||
json.dump(merged, f, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Patch the main OSS metadata index to advertise the plugins product.
|
||||
|
||||
Ensures the top-level ``metadata/index.json`` has a ``products.plugins``
|
||||
entry pointing to the plugins sub-index.
|
||||
|
||||
Usage::
|
||||
|
||||
python scripts/pack/patch_main_index.py \
|
||||
--index main-index.json \
|
||||
--out main-index.json
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def patch_index(index: dict) -> dict:
|
||||
"""Add/update the ``plugins`` product entry (mutates *index*)."""
|
||||
index.setdefault("products", {})
|
||||
index["products"]["plugins"] = {
|
||||
"name": {"zh-CN": "插件", "en-US": "Plugins"},
|
||||
"index_url": "/metadata/plugins/index.json",
|
||||
}
|
||||
index["updated_at"] = datetime.now(timezone.utc).isoformat()
|
||||
return index
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> None:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Patch main metadata index with plugins product entry.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--index",
|
||||
required=True,
|
||||
type=Path,
|
||||
help="Path to the main index.json",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--out",
|
||||
required=True,
|
||||
type=Path,
|
||||
help="Output path for the patched index.json",
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
with open(args.index, encoding="utf-8") as f:
|
||||
index = json.load(f)
|
||||
|
||||
patched = patch_index(index)
|
||||
|
||||
with open(args.out, "w", encoding="utf-8") as f:
|
||||
json.dump(patched, f, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user