Commit 27a20cb
[adapter] refactor: tidy _resolve_checkpoint_path call sites (#161)
* [adapter] refactor: hoist os.path.expanduser into _resolve_checkpoint_path
Move the `path = os.path.expanduser(path)` call out of `load_checkpoint`
and into `_resolve_checkpoint_path` itself. The resolver is now the
single entry point that takes a raw user-provided spec and returns a
usable local directory; callers no longer need to remember to normalize
`~` separately.
Safe in all three input branches:
- Local path with `~`: expanded correctly (unchanged behavior).
- Local path without `~`: no-op.
- HF spec ('owner/repo' or 'hf://...'): no-op since `expanduser`
only acts on a leading `~`.
Co-authored-by: Cursor <cursoragent@cursor.com>
* [adapter] refactor: drop dead exists-check; collapse `spec` local
Two small cleanups in the HF-checkpoint resolve path, both follow-ups
to the un-gating change:
A. Remove the dead `if not os.path.exists(path)` guard in
`load_checkpoint`. `_resolve_checkpoint_path` now either:
- returns a path it has just confirmed via `os.path.exists`, or
- returns a downloaded path that `download_hf_checkpoint` has
verified with `os.path.isdir`, or
- raises `FileNotFoundError` with the actual root cause.
The guard was useful pre-ungating (the old post-barrier
`snapshot_download` call could return a non-existent path on
cache-miss-after-failure); now it's unreachable AND its error
message would lie about the failure mode.
B. Collapse the redundant `spec` local in `_resolve_checkpoint_path`.
`parse_hf_checkpoint_path` already strips the `hf://` prefix
internally, and the local-path `os.path.exists` check is gated on
`not force_hf` so passing `path` (with the prefix still attached on
the HF branch) is safe. Removes one variable from the reader's
mental model.
Pure refactor: no behavior change. The 8 happy-path + 5 original-error
+ 6 path-traversal parser cases all still pass.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent bfd0f14 commit 27a20cb
1 file changed
Lines changed: 8 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1491 | 1491 | | |
1492 | 1492 | | |
1493 | 1493 | | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
1494 | 1497 | | |
1495 | | - | |
1496 | 1498 | | |
1497 | | - | |
1498 | | - | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
1499 | 1502 | | |
1500 | | - | |
| 1503 | + | |
| 1504 | + | |
1501 | 1505 | | |
1502 | 1506 | | |
1503 | 1507 | | |
| |||
1741 | 1745 | | |
1742 | 1746 | | |
1743 | 1747 | | |
1744 | | - | |
1745 | 1748 | | |
1746 | | - | |
1747 | | - | |
1748 | | - | |
1749 | | - | |
1750 | 1749 | | |
1751 | 1750 | | |
1752 | 1751 | | |
| |||
0 commit comments