mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 11:39:26 +08:00
fix(python-runtime): 修正过时的 Hatch 路径与安装写法(1.0.4)/ correct stale Hatch paths and install commands (#242)
python-runtime 与 dev-environment-setup 还在描述客户端 10.0.105 之前的 Hatch 布局:正常安装时没有 runtime/hatch/hatch,probe-python.sh 的 hatch_path 恒空,Agent 接着就会用系统包管理器。文档的 CLI 写法同样有问题:Hatch 1.16.5 里没有 HATCH_HOME 和 HATCH_PYTHON_MIRROR_URL,不带 --private --dir 的 python install 装到用户数据目录并改写 .zshrc、.zprofile,DesireCore 也看不到那个 Python。 - 二进制改为随包的 static/toolchains/<平台>-<架构>/hatch/hatch;runtime/hatch/hatch 只有手动下载后才存在 - 先用已在 PATH 上的内置 Python;指定版本用 runtime/hatch/local/<版本> 的绝对路径,pip 走探测到的解释器 - 安装命令带 --private --dir,环境变量改为 PYAPP_INSTALL_DIR_HATCH;换下载源用 HATCH_PYTHON_CUSTOM_SOURCE_<NAME>,并写明 URL 形态约束 - probe-python.sh 按新布局查找,新增 hatch_bootstrap,只认与二进制同版本的分发;没有解包好的分发时不执行二进制,避免 --version 触发下载;输出的路径字段做 JSON 转义 - 写明这个 bash 探测脚本在 Windows 上不查找 Hatch,降级到 L3 前先试 L2 的 Windows 路径 - 记录首启导入把本机镜像地址写进 hatch-dist.json,导致 local/ 上的 Hatch 命令报 Unknown distribution source,并给出修复办法;客户端修复见 desirecore/desirecore#5578 - desirecore-runtime.md 的源码路径改为 packages/agent-service/src;decision-tree.md 补上 standalone 的 401 - 版本 python-runtime 1.0.3 → 1.0.4、dev-environment-setup 2.0.5 → 2.0.6,sidecar 与 i18n source_hash 同步;不设客户端版本门槛 Correct the Hatch paths and install commands in python-runtime and dev-environment-setup, which still described the layout from before client 10.0.105 and told Agents to run an install that edits shell startup files and lands where DesireCore cannot see it. probe-python.sh now finds the current layout, reports the unpacked distribution, and no longer triggers a download. 验证:catalog metadata 与 i18n 校验 0 error,translate --check 通过,market-i18n-real-repo 22/22;真实 Hatch 1.16.5 在隔离 HOME 下逐条跑过文档命令;standalone 隔离 HOME + mock 模型下真实 Bash 工具按文档跑通,未调用真实模型;探测脚本覆盖多种布局及含引号、反斜杠的路径。Windows 写法只对照源码。私有敏感词扫描未执行,经用户确认后合并。
This commit is contained in:
11 files changed
+276
-106
No files matched your search
@@ -1,8 +1,32 @@
|
||||
# DesireCore 内置 Hatch(L1 / L2 主路径)
|
||||
|
||||
DesireCore 内置 [Hatch](https://hatch.pypa.io/) v1.16.5。Hatch 二进制随应用打包于 `static/hatch/`,运行时位于 `${DESIRECORE_ROOT}/runtime/hatch/`,**用户无需单独安装**。
|
||||
DesireCore 内置 [Hatch](https://hatch.pypa.io/) v1.16.5,**用户无需单独安装**。
|
||||
|
||||
> 与系统 Python 完全隔离:Hatch 安装的 Python 位于 `${DESIRECORE_ROOT}/runtime/hatch/local/<version>/`,不修改系统 PATH。
|
||||
| 内容 | 位置 |
|
||||
|------|------|
|
||||
| Hatch 二进制(随包,默认) | 应用目录下的 `static/toolchains/<平台>-<架构>/hatch/hatch`(Windows 为 `hatch.exe`)。应用目录在 macOS 是 `<App>.app/Contents`,其他平台是安装目录 |
|
||||
| Hatch 二进制(手动下载,存在时优先) | `${DESIRECORE_ROOT}/runtime/hatch/hatch`,只有随包二进制不可用、经 `POST /hatch/install` 下载后才存在 |
|
||||
| Hatch 分发(客户端 10.0.183 起) | `${DESIRECORE_ROOT}/runtime/hatch/bootstrap/<Hatch 版本>-<平台>-<架构>/`,客户端启动后从随包归档解包 |
|
||||
| 内置 Python | `${DESIRECORE_ROOT}/runtime/hatch/local/<版本>/python/bin/python3`(Windows 为 `python\python.exe`,pip 在旁边的 `Scripts\`) |
|
||||
|
||||
## 直接使用内置 Python(通常不需要安装)
|
||||
|
||||
客户端首次启动时导入一个内置 Python(目前是 3.13),可以直接用。DesireCore 把一个内置版本(推荐版本已安装就用它,否则取最高版本)的目录追加到服务进程 PATH 末尾,Bash 等工具都会继承,不改用户的 shell 配置。
|
||||
|
||||
- 系统没有 Python 时,直接运行 `python3`、`pip3`。
|
||||
- 系统已有 Python 时系统版本优先(Windows 商店跳转存根、macOS 缺开发者工具时的 `/usr/bin` 工具 shim 不算,内置目录会排在它们前面)。要用内置版本,写绝对路径。版本清单见 `<env>` 块的 Managed runtimes 段,或列目录:
|
||||
|
||||
```bash
|
||||
LOCAL="${DESIRECORE_ROOT}/runtime/hatch/local"
|
||||
ls "$LOCAL"
|
||||
|
||||
"$LOCAL/<版本>/python/bin/python3" --version
|
||||
"$LOCAL/<版本>/python/bin/python3" -m venv .venv
|
||||
```
|
||||
|
||||
Windows:`$env:DESIRECORE_ROOT\runtime\hatch\local\<版本>\python\python.exe`。
|
||||
|
||||
只有需要另一个版本时才用下面的 L1 / L2 安装。
|
||||
|
||||
## L1:通过 HTTP API 操作(推荐,DesireCore 应用内)
|
||||
|
||||
@@ -18,13 +42,16 @@ curl -sk --max-time 0.5 "${BASE}/environment" >/dev/null \
|
||||
|| { echo "API 超时,降级到 L2"; exit 1; }
|
||||
```
|
||||
|
||||
standalone 部署的接口要求实例令牌,Agent 没有,会返回 401,这时走 L2。桌面版的本机请求不需要令牌。
|
||||
|
||||
### 检查 Hatch 状态 / 安装
|
||||
|
||||
```bash
|
||||
# 状态:runtime/static 任一存在即 ready
|
||||
# 实际执行一次 hatch --version,解包还没完成时会先等它
|
||||
curl -sk "${BASE}/hatch/status"
|
||||
# → {"installed":true,"version":"1.16.5"}
|
||||
|
||||
# 若未就绪,触发自动下载
|
||||
# 随包 Hatch 可用时直接返回成功,否则下载到 runtime/hatch/
|
||||
curl -sk -X POST "${BASE}/hatch/install"
|
||||
```
|
||||
|
||||
@@ -33,16 +60,18 @@ curl -sk -X POST "${BASE}/hatch/install"
|
||||
```bash
|
||||
# 已安装版本
|
||||
curl -sk "${BASE}/python/installed"
|
||||
# → ["3.11", "3.12"]
|
||||
# → ["3.13"]
|
||||
|
||||
# 可安装版本(来自 Hatch python show)
|
||||
# 可安装版本(Hatch 内置清单,不联网;Hatch 不可用时回落到兜底清单)
|
||||
curl -sk "${BASE}/python/available"
|
||||
# → {"source":"live","versions":[{"name":"3.12","version":"3.12.12"}, ...]}
|
||||
|
||||
# 安装(异步,立即返回 taskId)
|
||||
# 安装(异步,立即返回 taskId)。version 填上面的 name,如 3.12,不是 3.12.12
|
||||
curl -sk -X POST "${BASE}/python/install" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"version":"3.12"}'
|
||||
# → { "taskId": "uuid" }
|
||||
# 首启导入还在进行时返回 409,稍后再试
|
||||
|
||||
# 移除
|
||||
curl -sk -X POST "${BASE}/python/remove" \
|
||||
@@ -50,17 +79,17 @@ curl -sk -X POST "${BASE}/python/remove" \
|
||||
-d '{"version":"3.10"}'
|
||||
```
|
||||
|
||||
### 订阅实时输出
|
||||
### 实时输出 / 缓存刷新
|
||||
|
||||
DesireCore 内部 Agent 默认连了 Socket.IO;外部脚本若未连,则 100ms 后任务静默执行。要看进度:
|
||||
DesireCore 内部界面连了 Socket.IO;在 Bash 里用 `curl` 调用时收不到输出,任务在 100ms 后静默执行。要看进度:
|
||||
|
||||
- 监听事件 `runtime:terminal`,payload `{ taskId, data }`,按 taskId 过滤
|
||||
- 任务结束事件 `runtime:complete`,payload `{ taskId, success }`
|
||||
|
||||
### 强制刷新缓存
|
||||
没有 Socket.IO 客户端时,轮询 `GET ${BASE}/python/installed`:安装时等目标版本出现,移除时等它消失。任务失败时轮询不会收到信号,服务日志里也没有原因,所以要设上限;超时后改走 L2,CLI 会直接打印报错。
|
||||
|
||||
```bash
|
||||
curl -sk -X POST "${BASE}/environment/refresh"
|
||||
curl -sk -X POST "${BASE}/environment/refresh" # 安装结束后刷新
|
||||
```
|
||||
|
||||
## L2:直接调用 Hatch CLI 绝对路径
|
||||
@@ -68,56 +97,85 @@ curl -sk -X POST "${BASE}/environment/refresh"
|
||||
### macOS / Linux
|
||||
|
||||
```bash
|
||||
HATCH=${DESIRECORE_ROOT}/runtime/hatch/hatch
|
||||
export HATCH_HOME=${DESIRECORE_ROOT}/runtime/hatch
|
||||
# export HATCH_PYTHON_MIRROR_URL=... # 中国大陆加速可选
|
||||
SNAPSHOT=$(bash skills/python-runtime/scripts/probe-python.sh)
|
||||
|
||||
# 二进制路径取自探测结果,为空时见下方「找不到 Hatch 二进制」
|
||||
HATCH=$(echo "$SNAPSHOT" | jq -r .hatch_path)
|
||||
|
||||
# 每次调用都要设置:DesireCore 只在自己调用 Hatch 时设置它,不传给 Bash
|
||||
export PYAPP_INSTALL_DIR_HATCH=$(echo "$SNAPSHOT" | jq -r .hatch_bootstrap)
|
||||
|
||||
# 内置 Python 的目录,下面每条命令都要带上
|
||||
LOCAL="${DESIRECORE_ROOT}/runtime/hatch/local"
|
||||
|
||||
# 列出版本表
|
||||
"$HATCH" python show
|
||||
"$HATCH" python show --dir "$LOCAL"
|
||||
# Installed
|
||||
# ┌──────┬─────────┐
|
||||
# │ Name │ Version │
|
||||
# ├──────┼─────────┤
|
||||
# │ 3.13 │ 3.13.9 │
|
||||
# └──────┴─────────┘
|
||||
# Available
|
||||
# ┌──────────┬─────────┐
|
||||
# │ Name │ Version │
|
||||
# ├──────────┼─────────┤
|
||||
# │ 3.10 │ 3.10.16 │
|
||||
# │ 3.11 │ 3.11.11 │
|
||||
# │ 3.12 │ 3.12.8 │
|
||||
# │ 3.13 │ 3.13.1 │
|
||||
# │ pypy3.10 │ 7.3.17 │
|
||||
# │ 3.11 │ 3.11.14 │
|
||||
# │ 3.12 │ 3.12.12 │
|
||||
# │ 3.14 │ 3.14.0 │
|
||||
# └──────────┴─────────┘
|
||||
|
||||
# 安装
|
||||
"$HATCH" python install 3.12
|
||||
"$HATCH" python install 3.12 3.11 3.10 # 批量
|
||||
"$HATCH" python install 3.12 --private --dir="$LOCAL"
|
||||
"$HATCH" python install 3.11 3.10 --private --dir="$LOCAL" # 批量
|
||||
|
||||
# 已装版本(直接读目录最稳)
|
||||
ls ${DESIRECORE_ROOT}/runtime/hatch/local/
|
||||
ls "$LOCAL"
|
||||
|
||||
# 移除
|
||||
"$HATCH" python remove 3.11
|
||||
"$HATCH" python remove 3.11 --dir="$LOCAL"
|
||||
|
||||
# 查某个版本的路径
|
||||
"$HATCH" python find 3.12 --dir "$LOCAL"
|
||||
```
|
||||
|
||||
**`python install` 必须带 `--private --dir`。** 不带时 Hatch 装到用户数据目录(macOS 为 `~/Library/Application Support/hatch/pythons`),还会把它写进 `.zshrc`、`.zprofile` 等 shell 配置,而 DesireCore 看不到这个 Python。
|
||||
|
||||
**`PYAPP_INSTALL_DIR_HATCH` 指向客户端解包好的 Hatch 分发。** 随包的 `hatch` 只是 PyApp 引导程序,不带这个变量时,任何命令(包括 `--version`)第一次运行都要联网下载约 45MB 的分发,解压后在用户目录占约 160MB(macOS 为 `~/Library/Application Support/pyapp`、`~/Library/Caches/pyapp`)。探测结果里 `hatch_bootstrap` 为空,说明客户端早于 10.0.183,或者启动后的解包还没完成(`GET ${BASE}/hatch/status` 会等它完成)。
|
||||
|
||||
### 找不到 Hatch 二进制
|
||||
|
||||
`probe-python.sh` 依次查找 `${DESIRECORE_ROOT}/runtime/hatch/hatch`、`$DESIRECORE_STATIC_DIR` 下的工具链、`runtime/volta-home/bin/node` 的链接目标旁边的工具链,以及默认安装位置(`/Applications/*.app/Contents/static`、`/opt/*/static`)。应用装在别处时 `hatch_path` 为空(AppImage 每次启动的挂载路径都不同),这时走 L1,或按本文开头的表格到应用目录下找。
|
||||
|
||||
这个脚本是 bash 写的,在 Windows 上不查找 Hatch,`hatch_path` 恒为空,不代表没有 Hatch:走 L1,或用下面的 PowerShell 写法。
|
||||
|
||||
### Windows PowerShell
|
||||
|
||||
```powershell
|
||||
$Hatch = "$env:USERPROFILE\.desirecore\runtime\hatch\hatch.exe"
|
||||
$env:HATCH_HOME = "$env:USERPROFILE\.desirecore\runtime\hatch"
|
||||
# 手动下载过 Hatch 时改用 "$env:DESIRECORE_ROOT\runtime\hatch\hatch.exe"
|
||||
$Hatch = "<安装目录>\static\toolchains\win32-x64\hatch\hatch.exe"
|
||||
$env:PYAPP_INSTALL_DIR_HATCH = "$env:DESIRECORE_ROOT\runtime\hatch\bootstrap\<Hatch 版本>-win32-x64"
|
||||
$Local = "$env:DESIRECORE_ROOT\runtime\hatch\local"
|
||||
|
||||
& $Hatch python show
|
||||
& $Hatch python install 3.12
|
||||
& $Hatch python show --dir "$Local"
|
||||
& $Hatch python install 3.12 --private "--dir=$Local"
|
||||
```
|
||||
|
||||
Windows ARM64 随包的 `hatch-universal.exe` 是安装器,不能当 CLI 调用,这个平台走 L3。
|
||||
|
||||
### 使用 Hatch 安装的 Python
|
||||
|
||||
```bash
|
||||
# 直接用绝对路径
|
||||
${DESIRECORE_ROOT}/runtime/hatch/local/3.12/python/bin/python3 --version
|
||||
"$LOCAL/3.12/python/bin/python3" --version
|
||||
|
||||
# 创建项目级虚拟环境(venv 推荐)
|
||||
${DESIRECORE_ROOT}/runtime/hatch/local/3.12/python/bin/python3 -m venv .venv
|
||||
"$LOCAL/3.12/python/bin/python3" -m venv .venv
|
||||
source .venv/bin/activate
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
Windows:`%USERPROFILE%\.desirecore\runtime\hatch\local\3.12\python\python.exe`。
|
||||
Windows:`$env:DESIRECORE_ROOT\runtime\hatch\local\3.12\python\python.exe`,pip 在同级的 `Scripts\`。
|
||||
|
||||
## 可视化管理
|
||||
|
||||
@@ -130,9 +188,9 @@ DesireCore 应用 → 资源管理器(侧边栏文件夹图标)→ 计算资
|
||||
| 安装方式 | 随应用自动内置 | 用户手动安装 |
|
||||
| Python 存放 | `${DESIRECORE_ROOT}/runtime/hatch/local/` | `~/.pyenv/versions/` |
|
||||
| 版本切换 | 绝对路径 / venv | shell PATH (`pyenv global/local`) |
|
||||
| 系统影响 | 完全隔离 | 修改 shell 启动脚本 |
|
||||
| 系统影响 | 带 `--private` 时完全隔离 | 修改 shell 启动脚本 |
|
||||
| GUI | DesireCore 运行环境 Tab | 无 |
|
||||
| 镜像加速 | `HATCH_PYTHON_MIRROR_URL` 环境变量 | `PYTHON_BUILD_MIRROR_URL` |
|
||||
| 自定义下载源 | `HATCH_PYTHON_CUSTOM_SOURCE_<NAME>` 环境变量 | `PYTHON_BUILD_MIRROR_URL` |
|
||||
| 适用 | 技能执行环境(强隔离) | 系统级日常开发 |
|
||||
|
||||
**结论**:DesireCore 应用内、有 Hatch 时永远首选 Hatch;外部脚本/独立项目可考虑 pyenv。
|
||||
@@ -141,7 +199,32 @@ DesireCore 应用 → 资源管理器(侧边栏文件夹图标)→ 计算资
|
||||
|
||||
| 现象 | 排查 |
|
||||
|------|------|
|
||||
| `${DESIRECORE_ROOT}/runtime/hatch/hatch: not found` | 二进制未释放。先 `POST /api/runtime/hatch/install` 触发下载 |
|
||||
| Hatch 安装 Python 时网络超时 | 设置 `HATCH_PYTHON_MIRROR_URL` 镜像 |
|
||||
| 多版本共存路径混乱 | Hatch 永远绝对路径调用,**不要**写入 PATH |
|
||||
| macOS Gatekeeper 阻止运行 | `xattr -d com.apple.quarantine ${DESIRECORE_ROOT}/runtime/hatch/hatch` |
|
||||
| `${DESIRECORE_ROOT}/runtime/hatch/hatch: not found` | 这个文件只有手动下载后才存在,属于正常情况。用随包二进制,见「找不到 Hatch 二进制」 |
|
||||
| `ValueError: Unknown distribution source: http://127.0.0.1:...` | 见下方「修复首启导入留下的来源记录」 |
|
||||
| `python install` 成功但 `local/` 里没有这个版本,`.zshrc` 多了一段 `export PATH` | 没带 `--private --dir`。用正确的参数重新安装;`"$HATCH" python remove <版本>`(不带 `--dir`)移除装错的那份,再删掉 shell 配置里 `Created by userpath` 那段 |
|
||||
| `hatch --version` 卡住很久 | 没带 `PYAPP_INSTALL_DIR_HATCH`,正在下载 Hatch 分发 |
|
||||
| Hatch 安装 Python 时网络超时 | 可以重试。需要换下载源时设 `HATCH_PYTHON_CUSTOM_SOURCE_<NAME>`:完整归档 URL,加号写成 `%2B`,路径里必须有 `/python-build-standalone/releases/download/`,否则这个地址被记进 `hatch-dist.json` 后同样会报 `Unknown distribution source`;`<NAME>` 是大写的版本名,点换成下划线,如 `3_12`。`hatch python install --help` 里写的 `HATCH_PYTHON_SOURCE_<NAME>` 在 1.16.5 上不生效 |
|
||||
| 多版本共存路径混乱 | Hatch 永远绝对路径调用,**不要**把版本目录手动写进 PATH |
|
||||
| macOS Gatekeeper 阻止手动下载的二进制 | `xattr -d com.apple.quarantine "${DESIRECORE_ROOT}/runtime/hatch/hatch"` |
|
||||
|
||||
### 修复首启导入留下的来源记录
|
||||
|
||||
首次启动从随包归档导入 Python 时,下载地址是本机镜像,这个地址被记进了 `local/<版本>/hatch-dist.json`。Hatch 不认它,所以只要 `local/` 里有这样的版本,针对这个目录的 `python install`、`python remove`、`python show` 都会报 `ValueError: Unknown distribution source`,走 HTTP API 也一样(任务静默失败)。内置 Python 本身不受影响,可以继续用。
|
||||
|
||||
把记录改回官方地址就能恢复,归档内容与官方相同:
|
||||
|
||||
```bash
|
||||
for f in "${DESIRECORE_ROOT}"/runtime/hatch/local/*/hatch-dist.json; do
|
||||
sed 's#http://127\.0\.0\.1:[0-9]*/runtime-mirror/python/#https://github.com/astral-sh/python-build-standalone/releases/download/#' "$f" > "$f.tmp" \
|
||||
&& mv "$f.tmp" "$f"
|
||||
done
|
||||
```
|
||||
|
||||
PowerShell:
|
||||
|
||||
```powershell
|
||||
Get-ChildItem "$env:DESIRECORE_ROOT\runtime\hatch\local\*\hatch-dist.json" | ForEach-Object {
|
||||
$text = (Get-Content -Raw $_.FullName) -replace 'http://127\.0\.0\.1:\d+/runtime-mirror/python/', 'https://github.com/astral-sh/python-build-standalone/releases/download/'
|
||||
[System.IO.File]::WriteAllText($_.FullName, $text)
|
||||
}
|
||||
```
|
||||
@@ -8,6 +8,7 @@
|
||||
# 1. 找一下二进制
|
||||
which python3 2>/dev/null; which python 2>/dev/null
|
||||
ls /usr/bin/python* /usr/local/bin/python* /opt/homebrew/bin/python* 2>/dev/null
|
||||
ls "${DESIRECORE_ROOT}"/runtime/hatch/local/*/python/bin/python3 2>/dev/null # DesireCore 内置
|
||||
|
||||
# 2. 查 PATH
|
||||
echo "$PATH" | tr ':' '\n' | head -20
|
||||
@@ -157,7 +158,8 @@ probe-python.sh 输出后,按字段快速判断:
|
||||
|------|------|----------|
|
||||
| `system_python.version` | 非空且 ≥ 3.8 | 未装 Python 或版本太低 |
|
||||
| `system_pip.version` | 非空 | pip 未装(macOS Apple 自带 Python 没有 pip) |
|
||||
| `hatch_path` | 非空 | DesireCore Hatch 未释放,调 `POST /api/runtime/hatch/install` |
|
||||
| `hatch_path` | 非空 | 没找到 DesireCore Hatch,通常是应用装在非默认位置。走 L1,见 `hatch-desirecore.md` 的「找不到 Hatch 二进制」 |
|
||||
| `hatch_bootstrap` | 非空 | Hatch 分发解包还没完成或客户端早于 10.0.183,直接调用会先联网下载,见 `hatch-desirecore.md` |
|
||||
| `pep668: true` | — | 系统 Python 受保护,必须 venv/pipx |
|
||||
| `active_venv` | 操作前为空,激活后非空 | venv 未生效,重新 `source .venv/bin/activate` |
|
||||
|
||||
|
||||
Reference in new issue
Block a user