mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 20:19:32 +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
@@ -13,7 +13,7 @@ description: >-
|
|||||||
cross-cutting environment question. 使用场景:用户提到 环境配置、PATH、
|
cross-cutting environment question. 使用场景:用户提到 环境配置、PATH、
|
||||||
容器、Docker、Podman、WSL、WSL2、办公依赖、系统工具,或不确定属于 Python /
|
容器、Docker、Podman、WSL、WSL2、办公依赖、系统工具,或不确定属于 Python /
|
||||||
Node.js 时的入口指引。
|
Node.js 时的入口指引。
|
||||||
version: 2.0.5
|
version: 2.0.6
|
||||||
type: procedural
|
type: procedural
|
||||||
risk_level: low
|
risk_level: low
|
||||||
status: enabled
|
status: enabled
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
},
|
},
|
||||||
"release": {
|
"release": {
|
||||||
"state": "known",
|
"state": "known",
|
||||||
"version": "2.0.5",
|
"version": "2.0.6",
|
||||||
"versionScheme": "semver"
|
"versionScheme": "semver"
|
||||||
},
|
},
|
||||||
"timestamps": {
|
"timestamps": {
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ curl -sk -X POST "${BASE}/python/install" \
|
|||||||
|
|
||||||
**判定失败的信号**
|
**判定失败的信号**
|
||||||
|
|
||||||
- HTTP 状态码 ≥ 500 或 502(远端镜像不可用,详见 runtime-env-routes.ts 130/162 行)
|
- HTTP 状态码 ≥ 500 或 502(远端镜像不可用,见 `runtime-env-routes.ts`)
|
||||||
|
- HTTP 401:standalone 部署的接口要求实例令牌,Agent 没有
|
||||||
- `runtime:complete` 事件 `success: false`
|
- `runtime:complete` 事件 `success: false`
|
||||||
- Socket.IO 连接断开后超过 30 秒未收到 `runtime:complete`
|
- Socket.IO 连接断开后超过 30 秒未收到 `runtime:complete`
|
||||||
|
|
||||||
@@ -74,32 +75,33 @@ curl -sk -X POST "${BASE}/python/install" \
|
|||||||
**典型操作(macOS / Linux)**
|
**典型操作(macOS / Linux)**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
HATCH=${DESIRECORE_ROOT}/runtime/hatch/hatch
|
PY_PROBE=$(bash skills/python-runtime/scripts/probe-python.sh)
|
||||||
|
HATCH=$(echo "$PY_PROBE" | jq -r .hatch_path)
|
||||||
VOLTA=$(bash skills/nodejs-runtime/scripts/probe-node.sh | jq -r .volta_path)
|
VOLTA=$(bash skills/nodejs-runtime/scripts/probe-node.sh | jq -r .volta_path)
|
||||||
|
|
||||||
export HATCH_HOME=${DESIRECORE_ROOT}/runtime/hatch
|
export PYAPP_INSTALL_DIR_HATCH=$(echo "$PY_PROBE" | jq -r .hatch_bootstrap)
|
||||||
export VOLTA_HOME="${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}"
|
export VOLTA_HOME="${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}"
|
||||||
export VOLTA_FEATURE_PNPM=1
|
export VOLTA_FEATURE_PNPM=1
|
||||||
|
|
||||||
"$HATCH" python install 3.12
|
"$HATCH" python install 3.12 --private --dir="${DESIRECORE_ROOT}/runtime/hatch/local"
|
||||||
"$VOLTA" fetch node@22
|
"$VOLTA" fetch node@22
|
||||||
```
|
```
|
||||||
|
|
||||||
**典型操作(Windows PowerShell)**
|
**典型操作(Windows PowerShell)**
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
$Hatch = "$env:USERPROFILE\.desirecore\runtime\hatch\hatch.exe"
|
$Hatch = "<安装目录>\static\toolchains\win32-x64\hatch\hatch.exe"
|
||||||
$Volta = "<安装目录>\static\toolchains\win32-x64\volta\volta.exe" # ARM 为 win32-arm64
|
$Volta = "<安装目录>\static\toolchains\win32-x64\volta\volta.exe" # ARM 为 win32-arm64
|
||||||
|
|
||||||
$env:HATCH_HOME = "$env:USERPROFILE\.desirecore\runtime\hatch"
|
$env:PYAPP_INSTALL_DIR_HATCH = "$env:DESIRECORE_ROOT\runtime\hatch\bootstrap\<Hatch 版本>-win32-x64"
|
||||||
if (-not $env:VOLTA_HOME) { $env:VOLTA_HOME = "$env:DESIRECORE_ROOT\runtime\volta-home" }
|
if (-not $env:VOLTA_HOME) { $env:VOLTA_HOME = "$env:DESIRECORE_ROOT\runtime\volta-home" }
|
||||||
$env:VOLTA_FEATURE_PNPM = "1"
|
$env:VOLTA_FEATURE_PNPM = "1"
|
||||||
|
|
||||||
& $Hatch python install 3.12
|
& $Hatch python install 3.12 --private "--dir=$env:DESIRECORE_ROOT\runtime\hatch\local"
|
||||||
& $Volta fetch node@22
|
& $Volta fetch node@22
|
||||||
```
|
```
|
||||||
|
|
||||||
Volta 二进制与 Volta Home 的位置见 `desirecore-runtime.md` 第一节。
|
Hatch、Volta 二进制和 Volta Home 的位置见 `desirecore-runtime.md` 第一节。`python install` 必须带 `--private --dir`,否则 Hatch 装到用户数据目录并改写 shell 配置;报 `Unknown distribution source` 时见 `python-runtime/references/hatch-desirecore.md`。
|
||||||
|
|
||||||
**判定失败的信号**
|
**判定失败的信号**
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,18 @@ DesireCore 内置了完整的开发环境管理基础设施。`python-runtime`
|
|||||||
|
|
||||||
### Hatch(Python 项目与版本管理器,v1.16.5)
|
### Hatch(Python 项目与版本管理器,v1.16.5)
|
||||||
|
|
||||||
| 平台 | 运行时绝对路径(用户安装版,优先) | 静态打包兜底 |
|
| 平台 | 手动下载(存在时优先) | 随包(默认) |
|
||||||
|------|----------------------------------|--------------|
|
|------|------------------------|--------------|
|
||||||
| macOS / Linux | `${DESIRECORE_ROOT}/runtime/hatch/hatch` | 应用包内 `static/hatch/hatch` |
|
| macOS / Linux | `${DESIRECORE_ROOT}/runtime/hatch/hatch` | 应用目录下 `static/toolchains/<平台>-<架构>/hatch/hatch` |
|
||||||
| Windows | `%USERPROFILE%\.desirecore\runtime\hatch\hatch.exe` | 应用包内 `static/hatch/hatch.exe` |
|
| Windows | `$env:DESIRECORE_ROOT\runtime\hatch\hatch.exe` | 应用目录下 `static\toolchains\win32-x64\hatch\hatch.exe` |
|
||||||
|
|
||||||
**Python 版本安装目录**:`${DESIRECORE_ROOT}/runtime/hatch/local/<版本>/python/bin/python3`(macOS/Linux),Windows 为 `python.exe`。
|
应用目录在 macOS 是 `<App>.app/Contents`,其他平台是安装目录。`runtime/hatch/` 下只有手动下载 Hatch 后才有二进制。Windows ARM64 随包的 `hatch-universal.exe` 是安装器,不能当 CLI 调用。
|
||||||
|
|
||||||
|
**Hatch 分发**:`${DESIRECORE_ROOT}/runtime/hatch/bootstrap/<Hatch 版本>-<平台>-<架构>/`(客户端 10.0.183 起),客户端启动后从随包归档解包。随包的 `hatch` 只是 PyApp 引导程序,直接调用时用 `PYAPP_INSTALL_DIR_HATCH` 指向这里,否则任何命令(包括 `--version`)第一次运行都要联网下载约 45MB,并解压到用户目录。
|
||||||
|
|
||||||
|
**Python 版本安装目录**:`${DESIRECORE_ROOT}/runtime/hatch/local/<版本>/python/bin/python3`(macOS/Linux),Windows 为 `python\python.exe`,pip 在旁边的 `Scripts\`。安装时必须带 `--private --dir=<这个 local 目录>`,否则 Hatch 装到用户数据目录并改写 `.zshrc`、`.zprofile`。
|
||||||
|
|
||||||
|
**内置 Python 已在 PATH 上**:服务把一个版本的可执行文件目录追加到进程 PATH 末尾,Bash 等工具都会继承,所以通常直接用 `python3`、`pip3`。系统已有 Python 时系统版本优先,要用内置版本就写绝对路径。
|
||||||
|
|
||||||
### Volta(Node.js 工具链管理器,v2.0.2)
|
### Volta(Node.js 工具链管理器,v2.0.2)
|
||||||
|
|
||||||
@@ -32,19 +38,21 @@ DesireCore 内置了完整的开发环境管理基础设施。`python-runtime`
|
|||||||
|
|
||||||
### 优先级规则
|
### 优先级规则
|
||||||
|
|
||||||
`runtime/` 目录优先于 `static/`。当用户更新过 Hatch/Volta 时,新版本写入 `runtime/`,DesireCore 优先调用之。
|
`runtime/` 下的二进制优先于 `static/`。随包二进制可用时不会下载,只有它不可用时,`POST /hatch/install`、`POST /volta/install` 才写入 `runtime/`。
|
||||||
|
|
||||||
## 二、关键环境变量
|
## 二、关键环境变量
|
||||||
|
|
||||||
| 变量 | 作用 | 默认/示例 |
|
| 变量 | 作用 | 默认/示例 |
|
||||||
|------|------|----------|
|
|------|------|----------|
|
||||||
| `HATCH_HOME` | Hatch 工作目录 | `${DESIRECORE_ROOT}/runtime/hatch` |
|
| `PYAPP_INSTALL_DIR_HATCH` | Hatch 分发目录 | `${DESIRECORE_ROOT}/runtime/hatch/bootstrap/<Hatch 版本>-<平台>-<架构>` |
|
||||||
| `HATCH_PYTHON_MIRROR_URL` | Python 下载镜像 | 加速节点(中国大陆) |
|
| `HATCH_PYTHON_CUSTOM_SOURCE_<NAME>` | 覆盖某个 Python 版本的下载地址(完整归档 URL,加号写成 `%2B`,路径里必须有 `/python-build-standalone/releases/download/`) | `<NAME>` 是大写的版本名,点换成下划线,如 `3_12` |
|
||||||
| `VOLTA_HOME` | Volta 工作目录 | `${DESIRECORE_ROOT}/runtime/volta-home` |
|
| `VOLTA_HOME` | Volta 工作目录 | `${DESIRECORE_ROOT}/runtime/volta-home` |
|
||||||
| `VOLTA_FEATURE_PNPM` | 启用 pnpm 管理 | `1` |
|
| `VOLTA_FEATURE_PNPM` | 启用 pnpm 管理 | `1` |
|
||||||
|
|
||||||
DesireCore 只在自己调用 Hatch / Volta 时设置这些变量,不会传给 Bash 等工具;直接调用绝对路径 CLI 时需手动 export。
|
DesireCore 只在自己调用 Hatch / Volta 时设置这些变量,不会传给 Bash 等工具;直接调用绝对路径 CLI 时需手动 export。
|
||||||
|
|
||||||
|
客户端还会设置 `HATCH_HOME`,但 Hatch 1.16.5 不读这个变量,也没有 `HATCH_PYTHON_MIRROR_URL`,这两个都不用设。Python 的安装目录靠 `--dir` 指定。
|
||||||
|
|
||||||
## 三、HTTP API 速查表
|
## 三、HTTP API 速查表
|
||||||
|
|
||||||
DesireCore agent-service 启动后将端口写入 `${DESIRECORE_ROOT}/agent-service.port`。全部接口走 **HTTPS + 自签名证书**(curl 需要 `-k`)。
|
DesireCore agent-service 启动后将端口写入 `${DESIRECORE_ROOT}/agent-service.port`。全部接口走 **HTTPS + 自签名证书**(curl 需要 `-k`)。
|
||||||
@@ -65,8 +73,8 @@ BASE="https://127.0.0.1:${PORT}/api/runtime"
|
|||||||
|
|
||||||
| 方法 | 路径 | 说明 |
|
| 方法 | 路径 | 说明 |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
| GET | `/hatch/status` | 检查 Hatch 是否就绪(runtime/static 任一存在即可) |
|
| GET | `/hatch/status` | 实际执行一次 `hatch --version`,Hatch 分发还没解包完时会先等它;返回 `{ installed, version }` |
|
||||||
| POST | `/hatch/install` | 下载并安装 Hatch 到 `runtime/hatch/`(同步返回成功/失败) |
|
| POST | `/hatch/install` | 随包 Hatch 可用时直接返回成功,否则下载并安装到 `runtime/hatch/`(同步返回成功/失败) |
|
||||||
| GET | `/volta/status` | 检查 Volta 是否就绪 |
|
| GET | `/volta/status` | 检查 Volta 是否就绪 |
|
||||||
| POST | `/volta/install` | 随包 Volta 可用时直接返回成功,否则下载并安装到 `runtime/volta/` |
|
| POST | `/volta/install` | 随包 Volta 可用时直接返回成功,否则下载并安装到 `runtime/volta/` |
|
||||||
|
|
||||||
@@ -75,8 +83,8 @@ BASE="https://127.0.0.1:${PORT}/api/runtime"
|
|||||||
| 方法 | 路径 | 请求体 / 返回 |
|
| 方法 | 路径 | 请求体 / 返回 |
|
||||||
|------|------|--------------|
|
|------|------|--------------|
|
||||||
| GET | `/python/installed` | 返回已安装版本列表(`["3.11", "3.12"]`) |
|
| GET | `/python/installed` | 返回已安装版本列表(`["3.11", "3.12"]`) |
|
||||||
| GET | `/python/available` | 返回可安装版本(依赖 Hatch 元数据) |
|
| GET | `/python/available` | 返回可安装版本 `{ source, versions: [{ name, version }] }`(Hatch 内置清单,不联网;Hatch 不可用时回落到兜底清单) |
|
||||||
| POST | `/python/install` | `{ "version": "3.12" }` → `{ "taskId": "uuid" }`,订阅 `runtime:terminal` 流 |
|
| POST | `/python/install` | `{ "version": "3.12" }`(填上面的 `name`)→ `{ "taskId": "uuid" }`,订阅 `runtime:terminal` 流;首启导入进行中返回 409 |
|
||||||
| POST | `/python/remove` | `{ "version": "3.11" }` → `{ "taskId": "uuid" }` |
|
| POST | `/python/remove` | `{ "version": "3.11" }` → `{ "taskId": "uuid" }` |
|
||||||
|
|
||||||
### Node.js 版本管理
|
### Node.js 版本管理
|
||||||
@@ -126,11 +134,13 @@ fi
|
|||||||
|
|
||||||
## 六、EnvironmentSnapshot 数据结构
|
## 六、EnvironmentSnapshot 数据结构
|
||||||
|
|
||||||
`GET /api/runtime/environment` 返回结构(详见 `lib/agent-service/environment-detection.ts`):
|
`GET /api/runtime/environment` 返回结构(详见主仓库 `packages/agent-service/src/context/environment-detection.ts`):
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
type ToolDetection = {
|
type ToolDetection = {
|
||||||
available: boolean
|
available: boolean
|
||||||
|
status?: 'available' | 'not_found' | 'detection_failed' // detection_failed 只表示本次没有结论,不能据此建议安装
|
||||||
|
failureCode?: string
|
||||||
command?: string // 实际命令名(python3 / python)
|
command?: string // 实际命令名(python3 / python)
|
||||||
version?: string // 提取后的版本号
|
version?: string // 提取后的版本号
|
||||||
path?: string // which/where 解析的绝对路径
|
path?: string // which/where 解析的绝对路径
|
||||||
@@ -147,7 +157,11 @@ type EnvironmentSnapshot = {
|
|||||||
docker: ToolDetection
|
docker: ToolDetection
|
||||||
podman: ToolDetection
|
podman: ToolDetection
|
||||||
git: ToolDetection
|
git: ToolDetection
|
||||||
|
brew: ToolDetection
|
||||||
|
gh: ToolDetection
|
||||||
|
cuaDriver: ToolDetection
|
||||||
}
|
}
|
||||||
|
toolkits?: unknown[] // 命令行工具套件(如 FFmpeg)的检测结果
|
||||||
wsl?: {
|
wsl?: {
|
||||||
installed: boolean
|
installed: boolean
|
||||||
version?: string
|
version?: string
|
||||||
@@ -187,9 +201,10 @@ type EnvDiff = {
|
|||||||
|
|
||||||
## 八、参考源代码
|
## 八、参考源代码
|
||||||
|
|
||||||
| 模块 | 文件 | 行数(仓库 ~/Project/desirecore) |
|
| 模块 | 文件(主仓库) |
|
||||||
|------|------|----------------------------------|
|
|------|----------------|
|
||||||
| 工具检测 | `lib/agent-service/environment-detection.ts` | 1–310 |
|
| 工具检测 | `packages/agent-service/src/context/environment-detection.ts` |
|
||||||
| 工具链管理(Hatch/Volta + 版本安装) | `lib/agent-service/runtime-manager.ts` | 1–1165 |
|
| 工具链管理(Hatch/Volta + 版本安装) | `packages/agent-service/src/session/runtime-manager.ts` |
|
||||||
| HTTP 路由 | `lib/agent-service/routes/runtime-env-routes.ts` | 1–186 |
|
| 内置运行时进 PATH | `packages/agent-service/src/session/managed-runtime-path.ts` |
|
||||||
| 端口文件 | `${DESIRECORE_ROOT}/agent-service.port` | DesireCore 启动时写入 |
|
| HTTP 路由 | `packages/agent-service/src/routes/runtime-env-routes.ts` |
|
||||||
|
| 端口文件 | `${DESIRECORE_ROOT}/agent-service.port`,DesireCore 启动时写入 |
|
||||||
@@ -45,9 +45,10 @@ Windows 上 `wsl` 字段值类似 `{ "installed": true, "version": "2", "default
|
|||||||
"desirecore_api": "https://127.0.0.1:38291",
|
"desirecore_api": "https://127.0.0.1:38291",
|
||||||
"system_python": { "path": "/opt/homebrew/bin/python3", "version": "3.12.4" },
|
"system_python": { "path": "/opt/homebrew/bin/python3", "version": "3.12.4" },
|
||||||
"system_pip": { "path": "/opt/homebrew/bin/pip3", "version": "24.0" },
|
"system_pip": { "path": "/opt/homebrew/bin/pip3", "version": "24.0" },
|
||||||
"hatch_path": "/Users/example/.desirecore/runtime/hatch/hatch",
|
"hatch_path": "/Applications/DesireCore.app/Contents/static/toolchains/darwin-arm64/hatch/hatch",
|
||||||
"hatch_version": "1.16.5",
|
"hatch_version": "1.16.5",
|
||||||
"hatch_versions": ["3.11", "3.12"],
|
"hatch_bootstrap": "/Users/example/.desirecore/runtime/hatch/bootstrap/1.16.5-darwin-arm64",
|
||||||
|
"hatch_versions": ["3.13"],
|
||||||
"active_venv": "/Users/example/proj/.venv",
|
"active_venv": "/Users/example/proj/.venv",
|
||||||
"pep668": false,
|
"pep668": false,
|
||||||
"pyenv_path": "",
|
"pyenv_path": "",
|
||||||
@@ -56,7 +57,10 @@ Windows 上 `wsl` 字段值类似 `{ "installed": true, "version": "2", "default
|
|||||||
```
|
```
|
||||||
|
|
||||||
字段语义:
|
字段语义:
|
||||||
- `hatch_path` 空字符串表示二进制不存在
|
- `system_python` / `system_pip` 是 PATH 解析到的结果,可能是 DesireCore 追加到 PATH 的内置 Python
|
||||||
|
- `hatch_path` 空字符串表示没找到二进制,查找顺序见 `python-runtime/references/hatch-desirecore.md`;这个脚本在 Windows 上不查找 Hatch,恒为空
|
||||||
|
- `hatch_bootstrap` 是客户端解包好的 Hatch 分发目录,直接调用 Hatch 时经 `PYAPP_INSTALL_DIR_HATCH` 传入,版本与二进制一致;空字符串表示解包还没完成或客户端早于 10.0.183
|
||||||
|
- `hatch_version` 在 `hatch_bootstrap` 为空时读二进制旁边的 `asset.json`,读不到就是空字符串,不执行二进制(否则会触发下载)
|
||||||
- `hatch_versions` 是 `${DESIRECORE_ROOT}/runtime/hatch/local/` 下的目录列表(即已通过 Hatch 安装的 Python 版本)
|
- `hatch_versions` 是 `${DESIRECORE_ROOT}/runtime/hatch/local/` 下的目录列表(即已通过 Hatch 安装的 Python 版本)
|
||||||
- `active_venv` 取自 `$VIRTUAL_ENV` 环境变量
|
- `active_venv` 取自 `$VIRTUAL_ENV` 环境变量
|
||||||
- `pep668` 检测 `/usr/lib/python*/EXTERNALLY-MANAGED` 是否存在(Debian 12+/Ubuntu 23.04+ 启用)
|
- `pep668` 检测 `/usr/lib/python*/EXTERNALLY-MANAGED` 是否存在(Debian 12+/Ubuntu 23.04+ 启用)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ description: >-
|
|||||||
version", "pip command not found", or any Python-related runtime error.
|
version", "pip command not found", or any Python-related runtime error.
|
||||||
使用场景:用户需要 安装 Python、安装 pip、配置虚拟环境、管理多版本、
|
使用场景:用户需要 安装 Python、安装 pip、配置虚拟环境、管理多版本、
|
||||||
解决 PEP 668、import 失败、PATH 问题、SSL 证书错误等。
|
解决 PEP 668、import 失败、PATH 问题、SSL 证书错误等。
|
||||||
version: 1.0.3
|
version: 1.0.4
|
||||||
type: procedural
|
type: procedural
|
||||||
risk_level: low
|
risk_level: low
|
||||||
status: enabled
|
status: enabled
|
||||||
@@ -31,7 +31,7 @@ tags:
|
|||||||
- environment
|
- environment
|
||||||
metadata:
|
metadata:
|
||||||
author: desirecore
|
author: desirecore
|
||||||
updated_at: '2026-05-02'
|
updated_at: '2026-11-01'
|
||||||
i18n:
|
i18n:
|
||||||
default_locale: en-US
|
default_locale: en-US
|
||||||
source_locale: zh-CN
|
source_locale: zh-CN
|
||||||
@@ -44,7 +44,7 @@ metadata:
|
|||||||
description: >-
|
description: >-
|
||||||
Use this skill when the user needs to install, upgrade, or troubleshoot Python and pip environments. Covers four-tier fallback strategy: (1) DesireCore HTTP API for in-app installation, (2) DesireCore built-in Hatch CLI for Python version management, (3) system package managers (brew/apt/dnf/winget), (4) community pyenv as last resort. Also covers virtual environments (venv/pipx/conda), PEP 668 externally-managed errors, and import / PATH troubleshooting. Triggers include: "install python", "pip not found", "python not found", "PEP 668", "externally-managed", "venv", "virtualenv", "pipx", "conda", "miniconda", "pyenv", "hatch", "python version", "pip command not found", or any Python-related runtime error. 使用场景:用户需要 安装 Python、安装 pip、配置虚拟环境、管理多版本、 解决 PEP 668、import 失败、PATH 问题、SSL 证书错误等。
|
Use this skill when the user needs to install, upgrade, or troubleshoot Python and pip environments. Covers four-tier fallback strategy: (1) DesireCore HTTP API for in-app installation, (2) DesireCore built-in Hatch CLI for Python version management, (3) system package managers (brew/apt/dnf/winget), (4) community pyenv as last resort. Also covers virtual environments (venv/pipx/conda), PEP 668 externally-managed errors, and import / PATH troubleshooting. Triggers include: "install python", "pip not found", "python not found", "PEP 668", "externally-managed", "venv", "virtualenv", "pipx", "conda", "miniconda", "pyenv", "hatch", "python version", "pip command not found", or any Python-related runtime error. 使用场景:用户需要 安装 Python、安装 pip、配置虚拟环境、管理多版本、 解决 PEP 668、import 失败、PATH 问题、SSL 证书错误等。
|
||||||
body: ./SKILL.zh-CN.md
|
body: ./SKILL.zh-CN.md
|
||||||
source_hash: sha256:ea796e0282dc77af
|
source_hash: sha256:6d530a7932ec82f6
|
||||||
translated_by: human
|
translated_by: human
|
||||||
en-US:
|
en-US:
|
||||||
name: Python Runtime Management
|
name: Python Runtime Management
|
||||||
@@ -52,9 +52,9 @@ metadata:
|
|||||||
description: >-
|
description: >-
|
||||||
Use this skill when the user needs to install, upgrade, or troubleshoot Python and pip environments. Covers four-tier fallback strategy: (1) DesireCore HTTP API for in-app installation, (2) DesireCore built-in Hatch CLI for Python version management, (3) system package managers (brew/apt/dnf/winget), (4) community pyenv as last resort. Also covers virtual environments (venv/pipx/conda), PEP 668 externally-managed errors, and import / PATH troubleshooting. Triggers include: "install python", "pip not found", "python not found", "PEP 668", "externally-managed", "venv", "virtualenv", "pipx", "conda", "miniconda", "pyenv", "hatch", "python version", "pip command not found", or any Python-related runtime error. Use when the user needs to install Python, install pip, configure virtual environments, manage multiple versions, resolve PEP 668, import failures, PATH issues, SSL certificate errors, etc.
|
Use this skill when the user needs to install, upgrade, or troubleshoot Python and pip environments. Covers four-tier fallback strategy: (1) DesireCore HTTP API for in-app installation, (2) DesireCore built-in Hatch CLI for Python version management, (3) system package managers (brew/apt/dnf/winget), (4) community pyenv as last resort. Also covers virtual environments (venv/pipx/conda), PEP 668 externally-managed errors, and import / PATH troubleshooting. Triggers include: "install python", "pip not found", "python not found", "PEP 668", "externally-managed", "venv", "virtualenv", "pipx", "conda", "miniconda", "pyenv", "hatch", "python version", "pip command not found", or any Python-related runtime error. Use when the user needs to install Python, install pip, configure virtual environments, manage multiple versions, resolve PEP 668, import failures, PATH issues, SSL certificate errors, etc.
|
||||||
body: ./SKILL.md
|
body: ./SKILL.md
|
||||||
source_hash: sha256:585a14843750b051
|
source_hash: sha256:6d530a7932ec82f6
|
||||||
translated_by: human
|
translated_by: human
|
||||||
translated_at: '2026-05-03'
|
translated_at: '2026-11-01'
|
||||||
market:
|
market:
|
||||||
icon: >-
|
icon: >-
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0
|
||||||
@@ -88,9 +88,11 @@ between multiple Python versions / configure pip / create virtual environments
|
|||||||
import failures, PATH anomalies, and other Python runtime issues; or when
|
import failures, PATH anomalies, and other Python runtime issues; or when
|
||||||
another skill (docx / pdf / xlsx / pptx) reports "Python unavailable".
|
another skill (docx / pdf / xlsx / pptx) reports "Python unavailable".
|
||||||
|
|
||||||
**How to do it**: Prefer DesireCore's built-in Hatch, executing through the
|
**How to do it**: First check whether `python3` already works: DesireCore appends
|
||||||
four-tier fallback (HTTP API → Hatch CLI → system package manager
|
a managed Python directory to its service PATH, so nothing usually needs
|
||||||
brew/apt/dnf/winget → community solution pyenv).
|
installing. To install or switch versions, prefer DesireCore's built-in Hatch,
|
||||||
|
executing through the four-tier fallback (HTTP API → Hatch CLI → system package
|
||||||
|
manager brew/apt/dnf/winget → community solution pyenv).
|
||||||
|
|
||||||
## L1: Overview and Use Cases
|
## L1: Overview and Use Cases
|
||||||
|
|
||||||
@@ -131,11 +133,17 @@ Decide using `../dev-environment-setup/references/decision-tree.md`:
|
|||||||
|
|
||||||
| Condition | Path |
|
| Condition | Path |
|
||||||
|------|------|
|
|------|------|
|
||||||
|
| `system_python.path` non-empty and its version is sufficient | Use that interpreter directly, with pip through `"<system_python.path>" -m pip`; nothing to install |
|
||||||
|
| A specific version is needed and `hatch_versions` lists it | Absolute path `${DESIRECORE_ROOT}/runtime/hatch/local/<version>/python/bin/python3` (→ `references/hatch-desirecore.md`) |
|
||||||
| `desirecore_api` is non-empty | **L1** HTTP API |
|
| `desirecore_api` is non-empty | **L1** HTTP API |
|
||||||
| `desirecore_api` empty, `hatch_path` non-empty | **L2** Hatch CLI |
|
| `desirecore_api` empty, `hatch_path` non-empty | **L2** Hatch CLI |
|
||||||
| Neither of the above | **L3** system package manager (brew/apt/dnf/winget) |
|
| Neither of the above | **L3** system package manager (brew/apt/dnf/winget) |
|
||||||
| L1–L3 all fail or user explicitly requests | **L4** community solution (pyenv) |
|
| L1–L3 all fail or user explicitly requests | **L4** community solution (pyenv) |
|
||||||
|
|
||||||
|
`system_python` is whatever PATH resolves, which may be DesireCore's managed Python: one managed version is appended after the system directories, so a system `python3` wins when there is one. The Managed runtimes section of the `<env>` block lists the absolute path of every managed version.
|
||||||
|
|
||||||
|
This bash probe does not look for Hatch on Windows, so `hatch_path` stays empty there. Before falling to L3 on Windows, try the Windows path under L2.
|
||||||
|
|
||||||
### Step 3: Execute (only the main path is shown; see references for details)
|
### Step 3: Execute (only the main path is shown; see references for details)
|
||||||
|
|
||||||
#### L1: HTTP API (→ `references/hatch-desirecore.md`)
|
#### L1: HTTP API (→ `references/hatch-desirecore.md`)
|
||||||
@@ -147,7 +155,8 @@ BASE="https://127.0.0.1:${PORT}/api/runtime"
|
|||||||
# List installable versions
|
# List installable versions
|
||||||
curl -sk "${BASE}/python/available"
|
curl -sk "${BASE}/python/available"
|
||||||
|
|
||||||
# Trigger install (asynchronous; subscribe to runtime:terminal for progress)
|
# Trigger install (asynchronous; subscribe to runtime:terminal for progress).
|
||||||
|
# version is the name from the list above, such as 3.12, not 3.12.12
|
||||||
curl -sk -X POST "${BASE}/python/install" \
|
curl -sk -X POST "${BASE}/python/install" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"version":"3.12"}'
|
-d '{"version":"3.12"}'
|
||||||
@@ -159,17 +168,22 @@ curl -sk -X POST "${BASE}/environment/refresh"
|
|||||||
#### L2: Hatch CLI absolute path (→ `references/hatch-desirecore.md`)
|
#### L2: Hatch CLI absolute path (→ `references/hatch-desirecore.md`)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
HATCH=${DESIRECORE_ROOT}/runtime/hatch/hatch
|
HATCH=$(jq -r .hatch_path /tmp/py-probe.json)
|
||||||
export HATCH_HOME=${DESIRECORE_ROOT}/runtime/hatch
|
export PYAPP_INSTALL_DIR_HATCH=$(jq -r .hatch_bootstrap /tmp/py-probe.json)
|
||||||
|
LOCAL="${DESIRECORE_ROOT}/runtime/hatch/local"
|
||||||
|
|
||||||
"$HATCH" python install 3.12
|
"$HATCH" python install 3.12 --private --dir="$LOCAL"
|
||||||
"$HATCH" python show # List installed/installable versions
|
"$HATCH" python show --dir "$LOCAL" # List installed/installable versions
|
||||||
|
|
||||||
# Use the Hatch-installed Python directly
|
# Use the Hatch-installed Python directly
|
||||||
${DESIRECORE_ROOT}/runtime/hatch/local/3.12/python/bin/python3 -m venv .venv
|
"$LOCAL/3.12/python/bin/python3" -m venv .venv
|
||||||
```
|
```
|
||||||
|
|
||||||
Windows: `%USERPROFILE%\.desirecore\runtime\hatch\hatch.exe`.
|
Always pass `--private --dir`: without them Hatch installs into its user data directory and edits `.zshrc` and `.zprofile`, and DesireCore cannot see that Python. Set `PYAPP_INSTALL_DIR_HATCH` on every call: DesireCore sets it only for its own calls, not for Bash, and without it the first Hatch command downloads about 45 MB and unpacks it into the user directory. The binary ships at `static/toolchains/<platform>-<arch>/hatch/hatch` under the app directory; `runtime/hatch/hatch` exists only after a manual Hatch download.
|
||||||
|
|
||||||
|
`ValueError: Unknown distribution source` on these commands, or an L1 install that never completes, means the source recorded by the bundled first-start import needs repairing: see "修复首启导入留下的来源记录" in `references/hatch-desirecore.md`.
|
||||||
|
|
||||||
|
Windows: `<install dir>\static\toolchains\win32-x64\hatch\hatch.exe`, with `PYAPP_INSTALL_DIR_HATCH` at `$env:DESIRECORE_ROOT\runtime\hatch\bootstrap\<Hatch version>-win32-x64`.
|
||||||
|
|
||||||
#### L3: System Package Manager
|
#### L3: System Package Manager
|
||||||
|
|
||||||
@@ -209,6 +223,7 @@ When errors occur, look up `references/troubleshooting.md`:
|
|||||||
2. **Refresh after modifying the environment**: for L1 call `POST /api/runtime/environment/refresh`; for L2/L3/L4 re-run probe.
|
2. **Refresh after modifying the environment**: for L1 call `POST /api/runtime/environment/refresh`; for L2/L3/L4 re-run probe.
|
||||||
3. **Cross-skill collaboration**: when `docx` / `pdf` / `xlsx` / `pptx` report "Python unavailable", fall into L1/L2 install; for office dependency lookup see `../dev-environment-setup/references/office-deps.md`.
|
3. **Cross-skill collaboration**: when `docx` / `pdf` / `xlsx` / `pptx` report "Python unavailable", fall into L1/L2 install; for office dependency lookup see `../dev-environment-setup/references/office-deps.md`.
|
||||||
4. **Do not pollute system Python**: at the project level always use venv; for global CLI use pipx.
|
4. **Do not pollute system Python**: at the project level always use venv; for global CLI use pipx.
|
||||||
|
5. **Never run `hatch python install` without `--private --dir`**: it would write to the user's shell startup files and install where DesireCore cannot see it.
|
||||||
|
|
||||||
## References
|
## References
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ pip / 创建虚拟环境(venv / pipx / conda)/ 排查 `python: command not f
|
|||||||
PATH 异常 等 Python 运行时问题,或其他 skill(docx / pdf / xlsx / pptx)报告
|
PATH 异常 等 Python 运行时问题,或其他 skill(docx / pdf / xlsx / pptx)报告
|
||||||
"Python 不可用" 时。
|
"Python 不可用" 时。
|
||||||
|
|
||||||
**怎么做**:优先使用 DesireCore 内置 Hatch,按四级降级(HTTP API → Hatch CLI →
|
**怎么做**:先确认 `python3` 是否已可用:DesireCore 把内置 Python 目录追加到了服务 PATH,通常不需要安装。
|
||||||
|
需要安装或切换版本时,优先使用 DesireCore 内置 Hatch,按四级降级(HTTP API → Hatch CLI →
|
||||||
系统包管理器 brew/apt/dnf/winget → 社区方案 pyenv)执行。
|
系统包管理器 brew/apt/dnf/winget → 社区方案 pyenv)执行。
|
||||||
|
|
||||||
## L1:概述与使用场景
|
## L1:概述与使用场景
|
||||||
@@ -52,11 +53,17 @@ cat /tmp/py-probe.json | jq .
|
|||||||
|
|
||||||
| 条件 | 路径 |
|
| 条件 | 路径 |
|
||||||
|------|------|
|
|------|------|
|
||||||
|
| `system_python.path` 非空且版本够用 | 直接用这个解释器,pip 用 `"<system_python.path>" -m pip`,不需要安装 |
|
||||||
|
| 需要指定版本,且 `hatch_versions` 已列出 | 绝对路径 `${DESIRECORE_ROOT}/runtime/hatch/local/<version>/python/bin/python3`(→ `references/hatch-desirecore.md`) |
|
||||||
| `desirecore_api` 非空 | **L1** HTTP API |
|
| `desirecore_api` 非空 | **L1** HTTP API |
|
||||||
| `desirecore_api` 空,`hatch_path` 非空 | **L2** Hatch CLI |
|
| `desirecore_api` 空,`hatch_path` 非空 | **L2** Hatch CLI |
|
||||||
| 上述都不满足 | **L3** 系统包管理器(brew/apt/dnf/winget) |
|
| 上述都不满足 | **L3** 系统包管理器(brew/apt/dnf/winget) |
|
||||||
| L1–L3 全部失败或用户明示 | **L4** 社区方案(pyenv) |
|
| L1–L3 全部失败或用户明示 | **L4** 社区方案(pyenv) |
|
||||||
|
|
||||||
|
`system_python` 是 PATH 解析到的结果,可能就是 DesireCore 的内置 Python:一个内置版本追加在系统目录之后,系统有 `python3` 时系统版本优先。`<env>` 块的 Managed runtimes 段列出每个内置版本的绝对路径。
|
||||||
|
|
||||||
|
这个 bash 探测脚本在 Windows 上不查找 Hatch,`hatch_path` 恒为空。Windows 上降级到 L3 之前,先试 L2 里的 Windows 路径。
|
||||||
|
|
||||||
### 第三步:执行(仅展示主路径,详见各 references)
|
### 第三步:执行(仅展示主路径,详见各 references)
|
||||||
|
|
||||||
#### L1:HTTP API(→ `references/hatch-desirecore.md`)
|
#### L1:HTTP API(→ `references/hatch-desirecore.md`)
|
||||||
@@ -69,6 +76,7 @@ BASE="https://127.0.0.1:${PORT}/api/runtime"
|
|||||||
curl -sk "${BASE}/python/available"
|
curl -sk "${BASE}/python/available"
|
||||||
|
|
||||||
# 触发安装(异步,订阅 runtime:terminal 看进度)
|
# 触发安装(异步,订阅 runtime:terminal 看进度)
|
||||||
|
# version 填上面列表里的 name,如 3.12,不是 3.12.12
|
||||||
curl -sk -X POST "${BASE}/python/install" \
|
curl -sk -X POST "${BASE}/python/install" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"version":"3.12"}'
|
-d '{"version":"3.12"}'
|
||||||
@@ -80,17 +88,22 @@ curl -sk -X POST "${BASE}/environment/refresh"
|
|||||||
#### L2:Hatch CLI 绝对路径(→ `references/hatch-desirecore.md`)
|
#### L2:Hatch CLI 绝对路径(→ `references/hatch-desirecore.md`)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
HATCH=${DESIRECORE_ROOT}/runtime/hatch/hatch
|
HATCH=$(jq -r .hatch_path /tmp/py-probe.json)
|
||||||
export HATCH_HOME=${DESIRECORE_ROOT}/runtime/hatch
|
export PYAPP_INSTALL_DIR_HATCH=$(jq -r .hatch_bootstrap /tmp/py-probe.json)
|
||||||
|
LOCAL="${DESIRECORE_ROOT}/runtime/hatch/local"
|
||||||
|
|
||||||
"$HATCH" python install 3.12
|
"$HATCH" python install 3.12 --private --dir="$LOCAL"
|
||||||
"$HATCH" python show # 列出已安装/可装版本
|
"$HATCH" python show --dir "$LOCAL" # 列出已安装/可装版本
|
||||||
|
|
||||||
# 直接使用 Hatch 安装的 Python
|
# 直接使用 Hatch 安装的 Python
|
||||||
${DESIRECORE_ROOT}/runtime/hatch/local/3.12/python/bin/python3 -m venv .venv
|
"$LOCAL/3.12/python/bin/python3" -m venv .venv
|
||||||
```
|
```
|
||||||
|
|
||||||
Windows:`%USERPROFILE%\.desirecore\runtime\hatch\hatch.exe`。
|
必须带 `--private --dir`:不带时 Hatch 装到它的用户数据目录,还会改 `.zshrc`、`.zprofile`,而 DesireCore 看不到这个 Python。每次调用都要设置 `PYAPP_INSTALL_DIR_HATCH`:DesireCore 只在自己调用时设置,不传给 Bash;不设时第一条 Hatch 命令会下载约 45MB 并解压到用户目录。二进制随包位于应用目录下的 `static/toolchains/<平台>-<架构>/hatch/hatch`;`runtime/hatch/hatch` 只有手动下载 Hatch 后才存在。
|
||||||
|
|
||||||
|
这些命令报 `ValueError: Unknown distribution source`,或 L1 安装一直等不到结果,说明首启导入留下的来源记录需要修复:见 `references/hatch-desirecore.md` 的「修复首启导入留下的来源记录」。
|
||||||
|
|
||||||
|
Windows:`<安装目录>\static\toolchains\win32-x64\hatch\hatch.exe`,`PYAPP_INSTALL_DIR_HATCH` 为 `$env:DESIRECORE_ROOT\runtime\hatch\bootstrap\<Hatch 版本>-win32-x64`。
|
||||||
|
|
||||||
#### L3:系统包管理器
|
#### L3:系统包管理器
|
||||||
|
|
||||||
@@ -130,6 +143,7 @@ Windows:`%USERPROFILE%\.desirecore\runtime\hatch\hatch.exe`。
|
|||||||
2. **修改了环境后必须刷新**:L1 调 `POST /api/runtime/environment/refresh`;L2/L3/L4 重新跑 probe。
|
2. **修改了环境后必须刷新**:L1 调 `POST /api/runtime/environment/refresh`;L2/L3/L4 重新跑 probe。
|
||||||
3. **跨 skill 协作**:`docx` / `pdf` / `xlsx` / `pptx` 报"Python 不可用"时,进入 L1/L2 安装;办公依赖速查见 `../dev-environment-setup/references/office-deps.md`。
|
3. **跨 skill 协作**:`docx` / `pdf` / `xlsx` / `pptx` 报"Python 不可用"时,进入 L1/L2 安装;办公依赖速查见 `../dev-environment-setup/references/office-deps.md`。
|
||||||
4. **不污染系统 Python**:项目级别一律使用 venv,全局 CLI 用 pipx。
|
4. **不污染系统 Python**:项目级别一律使用 venv,全局 CLI 用 pipx。
|
||||||
|
5. **`hatch python install` 必须带 `--private --dir`**:否则会写用户的 shell 配置,还装到 DesireCore 看不到的地方。
|
||||||
|
|
||||||
## 引用关系
|
## 引用关系
|
||||||
|
|
||||||
|
|||||||
@@ -34,14 +34,14 @@
|
|||||||
},
|
},
|
||||||
"release": {
|
"release": {
|
||||||
"state": "known",
|
"state": "known",
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"versionScheme": "semver"
|
"versionScheme": "semver"
|
||||||
},
|
},
|
||||||
"timestamps": {
|
"timestamps": {
|
||||||
"catalogUpdatedAt": {
|
"catalogUpdatedAt": {
|
||||||
"state": "known",
|
"state": "known",
|
||||||
"value": "2026-07-07T13:14:31Z",
|
"value": "2026-11-01",
|
||||||
"precision": "second"
|
"precision": "day"
|
||||||
},
|
},
|
||||||
"releasePublishedAt": {
|
"releasePublishedAt": {
|
||||||
"state": "unknown"
|
"state": "unknown"
|
||||||
|
|||||||
@@ -1,8 +1,32 @@
|
|||||||
# DesireCore 内置 Hatch(L1 / L2 主路径)
|
# 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 应用内)
|
## L1:通过 HTTP API 操作(推荐,DesireCore 应用内)
|
||||||
|
|
||||||
@@ -18,13 +42,16 @@ curl -sk --max-time 0.5 "${BASE}/environment" >/dev/null \
|
|||||||
|| { echo "API 超时,降级到 L2"; exit 1; }
|
|| { echo "API 超时,降级到 L2"; exit 1; }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
standalone 部署的接口要求实例令牌,Agent 没有,会返回 401,这时走 L2。桌面版的本机请求不需要令牌。
|
||||||
|
|
||||||
### 检查 Hatch 状态 / 安装
|
### 检查 Hatch 状态 / 安装
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 状态:runtime/static 任一存在即 ready
|
# 实际执行一次 hatch --version,解包还没完成时会先等它
|
||||||
curl -sk "${BASE}/hatch/status"
|
curl -sk "${BASE}/hatch/status"
|
||||||
|
# → {"installed":true,"version":"1.16.5"}
|
||||||
|
|
||||||
# 若未就绪,触发自动下载
|
# 随包 Hatch 可用时直接返回成功,否则下载到 runtime/hatch/
|
||||||
curl -sk -X POST "${BASE}/hatch/install"
|
curl -sk -X POST "${BASE}/hatch/install"
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -33,16 +60,18 @@ curl -sk -X POST "${BASE}/hatch/install"
|
|||||||
```bash
|
```bash
|
||||||
# 已安装版本
|
# 已安装版本
|
||||||
curl -sk "${BASE}/python/installed"
|
curl -sk "${BASE}/python/installed"
|
||||||
# → ["3.11", "3.12"]
|
# → ["3.13"]
|
||||||
|
|
||||||
# 可安装版本(来自 Hatch python show)
|
# 可安装版本(Hatch 内置清单,不联网;Hatch 不可用时回落到兜底清单)
|
||||||
curl -sk "${BASE}/python/available"
|
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" \
|
curl -sk -X POST "${BASE}/python/install" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"version":"3.12"}'
|
-d '{"version":"3.12"}'
|
||||||
# → { "taskId": "uuid" }
|
# → { "taskId": "uuid" }
|
||||||
|
# 首启导入还在进行时返回 409,稍后再试
|
||||||
|
|
||||||
# 移除
|
# 移除
|
||||||
curl -sk -X POST "${BASE}/python/remove" \
|
curl -sk -X POST "${BASE}/python/remove" \
|
||||||
@@ -50,17 +79,17 @@ curl -sk -X POST "${BASE}/python/remove" \
|
|||||||
-d '{"version":"3.10"}'
|
-d '{"version":"3.10"}'
|
||||||
```
|
```
|
||||||
|
|
||||||
### 订阅实时输出
|
### 实时输出 / 缓存刷新
|
||||||
|
|
||||||
DesireCore 内部 Agent 默认连了 Socket.IO;外部脚本若未连,则 100ms 后任务静默执行。要看进度:
|
DesireCore 内部界面连了 Socket.IO;在 Bash 里用 `curl` 调用时收不到输出,任务在 100ms 后静默执行。要看进度:
|
||||||
|
|
||||||
- 监听事件 `runtime:terminal`,payload `{ taskId, data }`,按 taskId 过滤
|
- 监听事件 `runtime:terminal`,payload `{ taskId, data }`,按 taskId 过滤
|
||||||
- 任务结束事件 `runtime:complete`,payload `{ taskId, success }`
|
- 任务结束事件 `runtime:complete`,payload `{ taskId, success }`
|
||||||
|
|
||||||
### 强制刷新缓存
|
没有 Socket.IO 客户端时,轮询 `GET ${BASE}/python/installed`:安装时等目标版本出现,移除时等它消失。任务失败时轮询不会收到信号,服务日志里也没有原因,所以要设上限;超时后改走 L2,CLI 会直接打印报错。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -sk -X POST "${BASE}/environment/refresh"
|
curl -sk -X POST "${BASE}/environment/refresh" # 安装结束后刷新
|
||||||
```
|
```
|
||||||
|
|
||||||
## L2:直接调用 Hatch CLI 绝对路径
|
## L2:直接调用 Hatch CLI 绝对路径
|
||||||
@@ -68,56 +97,85 @@ curl -sk -X POST "${BASE}/environment/refresh"
|
|||||||
### macOS / Linux
|
### macOS / Linux
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
HATCH=${DESIRECORE_ROOT}/runtime/hatch/hatch
|
SNAPSHOT=$(bash skills/python-runtime/scripts/probe-python.sh)
|
||||||
export HATCH_HOME=${DESIRECORE_ROOT}/runtime/hatch
|
|
||||||
# export HATCH_PYTHON_MIRROR_URL=... # 中国大陆加速可选
|
# 二进制路径取自探测结果,为空时见下方「找不到 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 │
|
# │ Name │ Version │
|
||||||
# ├──────────┼─────────┤
|
# ├──────────┼─────────┤
|
||||||
# │ 3.10 │ 3.10.16 │
|
# │ 3.11 │ 3.11.14 │
|
||||||
# │ 3.11 │ 3.11.11 │
|
# │ 3.12 │ 3.12.12 │
|
||||||
# │ 3.12 │ 3.12.8 │
|
# │ 3.14 │ 3.14.0 │
|
||||||
# │ 3.13 │ 3.13.1 │
|
|
||||||
# │ pypy3.10 │ 7.3.17 │
|
|
||||||
# └──────────┴─────────┘
|
# └──────────┴─────────┘
|
||||||
|
|
||||||
# 安装
|
# 安装
|
||||||
"$HATCH" python install 3.12
|
"$HATCH" python install 3.12 --private --dir="$LOCAL"
|
||||||
"$HATCH" python install 3.12 3.11 3.10 # 批量
|
"$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
|
### Windows PowerShell
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
$Hatch = "$env:USERPROFILE\.desirecore\runtime\hatch\hatch.exe"
|
# 手动下载过 Hatch 时改用 "$env:DESIRECORE_ROOT\runtime\hatch\hatch.exe"
|
||||||
$env:HATCH_HOME = "$env:USERPROFILE\.desirecore\runtime\hatch"
|
$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 show --dir "$Local"
|
||||||
& $Hatch python install 3.12
|
& $Hatch python install 3.12 --private "--dir=$Local"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Windows ARM64 随包的 `hatch-universal.exe` 是安装器,不能当 CLI 调用,这个平台走 L3。
|
||||||
|
|
||||||
### 使用 Hatch 安装的 Python
|
### 使用 Hatch 安装的 Python
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 直接用绝对路径
|
# 直接用绝对路径
|
||||||
${DESIRECORE_ROOT}/runtime/hatch/local/3.12/python/bin/python3 --version
|
"$LOCAL/3.12/python/bin/python3" --version
|
||||||
|
|
||||||
# 创建项目级虚拟环境(venv 推荐)
|
# 创建项目级虚拟环境(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
|
source .venv/bin/activate
|
||||||
pip install -r requirements.txt
|
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/` |
|
| Python 存放 | `${DESIRECORE_ROOT}/runtime/hatch/local/` | `~/.pyenv/versions/` |
|
||||||
| 版本切换 | 绝对路径 / venv | shell PATH (`pyenv global/local`) |
|
| 版本切换 | 绝对路径 / venv | shell PATH (`pyenv global/local`) |
|
||||||
| 系统影响 | 完全隔离 | 修改 shell 启动脚本 |
|
| 系统影响 | 带 `--private` 时完全隔离 | 修改 shell 启动脚本 |
|
||||||
| GUI | DesireCore 运行环境 Tab | 无 |
|
| GUI | DesireCore 运行环境 Tab | 无 |
|
||||||
| 镜像加速 | `HATCH_PYTHON_MIRROR_URL` 环境变量 | `PYTHON_BUILD_MIRROR_URL` |
|
| 自定义下载源 | `HATCH_PYTHON_CUSTOM_SOURCE_<NAME>` 环境变量 | `PYTHON_BUILD_MIRROR_URL` |
|
||||||
| 适用 | 技能执行环境(强隔离) | 系统级日常开发 |
|
| 适用 | 技能执行环境(强隔离) | 系统级日常开发 |
|
||||||
|
|
||||||
**结论**:DesireCore 应用内、有 Hatch 时永远首选 Hatch;外部脚本/独立项目可考虑 pyenv。
|
**结论**:DesireCore 应用内、有 Hatch 时永远首选 Hatch;外部脚本/独立项目可考虑 pyenv。
|
||||||
@@ -141,7 +199,32 @@ DesireCore 应用 → 资源管理器(侧边栏文件夹图标)→ 计算资
|
|||||||
|
|
||||||
| 现象 | 排查 |
|
| 现象 | 排查 |
|
||||||
|------|------|
|
|------|------|
|
||||||
| `${DESIRECORE_ROOT}/runtime/hatch/hatch: not found` | 二进制未释放。先 `POST /api/runtime/hatch/install` 触发下载 |
|
| `${DESIRECORE_ROOT}/runtime/hatch/hatch: not found` | 这个文件只有手动下载后才存在,属于正常情况。用随包二进制,见「找不到 Hatch 二进制」 |
|
||||||
| Hatch 安装 Python 时网络超时 | 设置 `HATCH_PYTHON_MIRROR_URL` 镜像 |
|
| `ValueError: Unknown distribution source: http://127.0.0.1:...` | 见下方「修复首启导入留下的来源记录」 |
|
||||||
| 多版本共存路径混乱 | Hatch 永远绝对路径调用,**不要**写入 PATH |
|
| `python install` 成功但 `local/` 里没有这个版本,`.zshrc` 多了一段 `export PATH` | 没带 `--private --dir`。用正确的参数重新安装;`"$HATCH" python remove <版本>`(不带 `--dir`)移除装错的那份,再删掉 shell 配置里 `Created by userpath` 那段 |
|
||||||
| macOS Gatekeeper 阻止运行 | `xattr -d com.apple.quarantine ${DESIRECORE_ROOT}/runtime/hatch/hatch` |
|
| `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. 找一下二进制
|
# 1. 找一下二进制
|
||||||
which python3 2>/dev/null; which python 2>/dev/null
|
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 /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
|
# 2. 查 PATH
|
||||||
echo "$PATH" | tr ':' '\n' | head -20
|
echo "$PATH" | tr ':' '\n' | head -20
|
||||||
@@ -157,7 +158,8 @@ probe-python.sh 输出后,按字段快速判断:
|
|||||||
|------|------|----------|
|
|------|------|----------|
|
||||||
| `system_python.version` | 非空且 ≥ 3.8 | 未装 Python 或版本太低 |
|
| `system_python.version` | 非空且 ≥ 3.8 | 未装 Python 或版本太低 |
|
||||||
| `system_pip.version` | 非空 | pip 未装(macOS Apple 自带 Python 没有 pip) |
|
| `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 |
|
| `pep668: true` | — | 系统 Python 受保护,必须 venv/pipx |
|
||||||
| `active_venv` | 操作前为空,激活后非空 | venv 未生效,重新 `source .venv/bin/activate` |
|
| `active_venv` | 操作前为空,激活后非空 | venv 未生效,重新 `source .venv/bin/activate` |
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
|
# 路径里可能有反斜杠和双引号,写进 JSON 前要转义(调用时仍用原始路径)
|
||||||
|
json_escape() {
|
||||||
|
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
|
||||||
|
}
|
||||||
|
|
||||||
detect_tool() {
|
detect_tool() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
local path
|
local path
|
||||||
@@ -14,7 +19,7 @@ detect_tool() {
|
|||||||
fi
|
fi
|
||||||
local version
|
local version
|
||||||
version=$("$name" --version 2>&1 | head -n1 | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1)
|
version=$("$name" --version 2>&1 | head -n1 | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1)
|
||||||
printf '{"path":"%s","version":"%s"}' "$path" "${version:-}"
|
printf '{"path":"%s","version":"%s"}' "$(json_escape "$path")" "${version:-}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── 平台 ────────────────────────────────
|
# ── 平台 ────────────────────────────────
|
||||||
@@ -48,16 +53,45 @@ SYS_PIP=$(detect_tool pip3)
|
|||||||
[ "$(echo "$SYS_PIP" | grep -c '"path":""')" = "1" ] && SYS_PIP=$(detect_tool pip)
|
[ "$(echo "$SYS_PIP" | grep -c '"path":""')" = "1" ] && SYS_PIP=$(detect_tool pip)
|
||||||
|
|
||||||
# ── DesireCore Hatch ────────────────────
|
# ── DesireCore Hatch ────────────────────
|
||||||
HATCH_BIN="${DESIRECORE_ROOT}/runtime/hatch/hatch"
|
HATCH_DIR="${DESIRECORE_ROOT}/runtime/hatch"
|
||||||
|
HATCH_TARGET="${PLATFORM}-${ARCH}"
|
||||||
|
|
||||||
|
# 二进制与服务同序:手动下载的 runtime/hatch/hatch 优先,其次随包工具链。
|
||||||
|
# 桌面版的应用目录不在环境变量里,随包路径再看 Volta 入口的链接目标(只读链接,不执行入口;
|
||||||
|
# Volta 建入口时指向同一工具链目录下的 volta-shim,旧版升级后可能已断)和默认安装位置。
|
||||||
|
VOLTA_SHIM=$(readlink "${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}/bin/node" 2>/dev/null)
|
||||||
HATCH_PATH=""
|
HATCH_PATH=""
|
||||||
HATCH_VERSION=""
|
for HATCH_BIN in \
|
||||||
if [ -x "$HATCH_BIN" ]; then
|
"${HATCH_DIR}/hatch" \
|
||||||
HATCH_PATH="$HATCH_BIN"
|
"${DESIRECORE_STATIC_DIR}/toolchains/${HATCH_TARGET}/hatch/hatch" \
|
||||||
HATCH_VERSION=$("$HATCH_BIN" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1)
|
"${VOLTA_SHIM%/volta/*}/hatch/hatch" \
|
||||||
|
/Applications/*.app/Contents/static/toolchains/"${HATCH_TARGET}"/hatch/hatch \
|
||||||
|
/opt/*/static/toolchains/"${HATCH_TARGET}"/hatch/hatch
|
||||||
|
do
|
||||||
|
if [ -f "$HATCH_BIN" ] && [ -x "$HATCH_BIN" ]; then
|
||||||
|
HATCH_PATH="$HATCH_BIN"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# 随包二进制旁边的 asset.json 写着它的版本;手动下载的二进制没有这个文件
|
||||||
|
HATCH_VERSION=$(grep -m1 '"version"' "${HATCH_PATH%/*}/asset.json" 2>/dev/null | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1)
|
||||||
|
|
||||||
|
# 客户端解包好的 Hatch 分发(10.0.183 起),调用二进制时经 PYAPP_INSTALL_DIR_HATCH 传入。
|
||||||
|
# 版本已知时只认同版本的分发(旧版本的分发升级后不会清理),未知时取找到的最后一个
|
||||||
|
HATCH_BOOTSTRAP=""
|
||||||
|
for BOOTSTRAP_DIR in "${HATCH_DIR}/bootstrap/"${HATCH_VERSION:-*}"-${HATCH_TARGET}"; do
|
||||||
|
[ -f "${BOOTSTRAP_DIR}/.ready" ] && HATCH_BOOTSTRAP="$BOOTSTRAP_DIR"
|
||||||
|
done
|
||||||
|
|
||||||
|
# 随包 Hatch 是 PyApp 引导程序:没有解包好的分发时,连 --version 都会下载分发并解压到用户目录,
|
||||||
|
# 所以只在有分发时才执行二进制
|
||||||
|
if [ -n "$HATCH_PATH" ] && [ -n "$HATCH_BOOTSTRAP" ]; then
|
||||||
|
HATCH_VERSION=$(PYAPP_INSTALL_DIR_HATCH="$HATCH_BOOTSTRAP" "$HATCH_PATH" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Hatch 已安装的 Python 版本(直接读 local/ 目录,避免依赖 hatch 命令)
|
# Hatch 已安装的 Python 版本(直接读 local/ 目录,避免依赖 hatch 命令)
|
||||||
HATCH_LOCAL="${DESIRECORE_ROOT}/runtime/hatch/local"
|
HATCH_LOCAL="${HATCH_DIR}/local"
|
||||||
HATCH_VERSIONS="[]"
|
HATCH_VERSIONS="[]"
|
||||||
if [ -d "$HATCH_LOCAL" ]; then
|
if [ -d "$HATCH_LOCAL" ]; then
|
||||||
versions=$(ls -1 "$HATCH_LOCAL" 2>/dev/null | sort -V | tr '\n' ',' | sed 's/,$//')
|
versions=$(ls -1 "$HATCH_LOCAL" 2>/dev/null | sort -V | tr '\n' ',' | sed 's/,$//')
|
||||||
@@ -92,12 +126,13 @@ cat <<EOF
|
|||||||
"desirecore_api": "${DESIRECORE_API}",
|
"desirecore_api": "${DESIRECORE_API}",
|
||||||
"system_python": ${SYS_PY},
|
"system_python": ${SYS_PY},
|
||||||
"system_pip": ${SYS_PIP},
|
"system_pip": ${SYS_PIP},
|
||||||
"hatch_path": "${HATCH_PATH}",
|
"hatch_path": "$(json_escape "$HATCH_PATH")",
|
||||||
"hatch_version": "${HATCH_VERSION}",
|
"hatch_version": "${HATCH_VERSION}",
|
||||||
|
"hatch_bootstrap": "$(json_escape "$HATCH_BOOTSTRAP")",
|
||||||
"hatch_versions": ${HATCH_VERSIONS},
|
"hatch_versions": ${HATCH_VERSIONS},
|
||||||
"active_venv": "${ACTIVE_VENV}",
|
"active_venv": "$(json_escape "$ACTIVE_VENV")",
|
||||||
"pep668": ${PEP668},
|
"pep668": ${PEP668},
|
||||||
"pyenv_path": "${PYENV_PATH:-}",
|
"pyenv_path": "$(json_escape "${PYENV_PATH:-}")",
|
||||||
"conda_path": "${CONDA_PATH:-}"
|
"conda_path": "$(json_escape "${CONDA_PATH:-}")"
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
Reference in new issue
Block a user