容错:把误带的 `workspaces/<当前ws>/` 前缀剥掉。 convert.py 的 `--dir` 用仓库根相对路径(`workspaces/ /raw/...`),而 k.py 的路径参数相对**当前 workspace**(`raw/...`)——两套口径新手极易混用, 混用时会拼出 `workspaces/ /workspaces/ /...` 的双重路径错误。 规则: - 前缀指向**当前激活** workspace → 自动剥掉,并在 stderr 提示; - 前缀指向**另一个真实存在的**
(arg: str)
| 1438 | |
| 1439 | |
| 1440 | def strip_workspace_prefix(arg: str) -> str: |
| 1441 | """容错:把误带的 `workspaces/<当前ws>/` 前缀剥掉。 |
| 1442 | |
| 1443 | convert.py 的 `--dir` 用仓库根相对路径(`workspaces/<ws>/raw/...`),而 |
| 1444 | k.py 的路径参数相对**当前 workspace**(`raw/...`)——两套口径新手极易混用, |
| 1445 | 混用时会拼出 `workspaces/<ws>/workspaces/<ws>/...` 的双重路径错误。 |
| 1446 | |
| 1447 | 规则: |
| 1448 | - 前缀指向**当前激活** workspace → 自动剥掉,并在 stderr 提示; |
| 1449 | - 前缀指向**另一个真实存在的** workspace → 抛 ValueError,提示改用 |
| 1450 | `--workspace <那个库>`(静默剥掉会读错库); |
| 1451 | - 其他情况原样返回。 |
| 1452 | """ |
| 1453 | norm = arg.replace("\\", "/").lstrip("./") |
| 1454 | parts = norm.split("/") |
| 1455 | if len(parts) < 3 or parts[0] != "workspaces": |
| 1456 | return arg |
| 1457 | if PROJECT_ROOT.parent.name != "workspaces": |
| 1458 | return arg # 未激活 workspace(如引擎根直跑),不做猜测 |
| 1459 | active = PROJECT_ROOT.name |
| 1460 | target_ws, rest = parts[1], "/".join(parts[2:]) |
| 1461 | if target_ws == active: |
| 1462 | print( |
| 1463 | f"提示: k.py 的路径相对当前 workspace({active})," |
| 1464 | f"已自动剥掉前缀 workspaces/{active}/", |
| 1465 | file=sys.stderr, |
| 1466 | ) |
| 1467 | return rest |
| 1468 | if (PROJECT_ROOT.parent / target_ws).is_dir(): |
| 1469 | raise ValueError( |
| 1470 | f"路径指向另一个 workspace {target_ws!r}(当前是 {active!r})。" |
| 1471 | f"请改用:python scripts/k.py --workspace {target_ws} <子命令> {rest}" |
| 1472 | ) |
| 1473 | return arg |
| 1474 | |
| 1475 | |
| 1476 | def resolve_doc_path(arg: str) -> Path: |
no outgoing calls
no test coverage detected