fix: 修复 hatchling readme 路径越界导致的后端构建失败 + dev.sh bash 3.2 兼容 - #180
Open
len0day wants to merge 2 commits into
Open
fix: 修复 hatchling readme 路径越界导致的后端构建失败 + dev.sh bash 3.2 兼容#180len0day wants to merge 2 commits into
len0day wants to merge 2 commits into
Conversation
新版 hatchling 校验要求 readme 必须位于项目目录内,readme = "../README.md" 导致 uv sync 构建 editable 包时直接失败。改为在 backend/ 下放置指向根 README 的软链,pyproject 的 readme 指向 "README.md",根 README 仍是唯一 内容来源。 uv.lock 同步为当前 pyproject 的解析结果:补上 shy3130#151 合并后缺失的 pypinyin 0.55.0,并把 lock 中后端版本从 0.1.83 更新到 0.1.88。 已验证:删除 .venv 后 uv sync 成功,uvicorn 正常启动,应用加载完成。
macOS 自带 bash 3.2 在 set -u 下展开空数组 ${#ARR[@]} 会报 unbound
variable,导致 BACKEND_EXTRAS 为空时启动直接失败。改用
${#BACKEND_EXTRA_ARGS[@]:-0} 兜底。
已验证:本机 bash 3.2 下 ./dev.sh 前后端均正常启动。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题与复现
在新版 hatchling 下执行
uv sync(或任何需要构建 backend 包的操作)直接失败:另外在 macOS 自带 bash 3.2 下运行
./dev.sh,当BACKEND_EXTRAS为空时因set -u下空数组${#ARR[@]}展开报 unbound variable 直接退出。根因
pyproject.toml的readme = "../README.md"指向项目目录之外,新版 hatchling 的 metadata 校验(metadata/core.py中readme属性校验)明确禁止该情况。dev.sh在set -euo pipefail下用${#BACKEND_EXTRA_ARGS[@]}判断 extras,bash 3.2 对空数组做#展开仍视为 unbound,bash 4.x 行为不同。uv.lock未同步(lock 中后端版本仍是 0.1.83、缺少 pypinyin),与 pyproject 不一致。解决方案
backend/README.md新增软链接指向根README,pyproject.toml的 readme 改为"README.md":根 README 仍是唯一内容来源,不产生两份拷贝。dev.sh改用${#BACKEND_EXTRA_ARGS[@]:-0}兜底,兼容 bash 3.2/4.x。uv.lock同步为当前 pyproject 的解析结果(补 pypinyin 0.55.0,后端版本 0.1.83 → 0.1.88,registry 保持清华源不变)。兼容性
uv sync --locked不再与 pyproject 冲突;清华源 URL 保持原样。性能
纯构建/启动脚本修复,不进入任何运行时热路径。
验证结果
.venv后uv sync成功安装全部 122 个包(macOS arm64 / Python 3.12.12)。./dev.sh在本机 bash 3.2 下前后端均正常启动:backend:3018OpenAPI 200、frontend:3011200;应用启动日志显示 18 条策略加载、enriched 缓存计算完成、matrix cache 预热成功。git diff --check通过。界面证据
无界面变化,不适用。
风险与回滚