feat(models): honor extra_model_paths.yaml in download/list/remove#439
feat(models): honor extra_model_paths.yaml in download/list/remove#439
Conversation
Add a parser for ComfyUI's extra_model_paths.yaml and wire it into the three model subcommands so users with models stored outside the workspace tree get them recognized by comfy-cli. The parser mirrors upstream's parsing behavior and add_model_folder_path priority semantics (last is_default wins for slot 0, legacy aliases unet and clip, multi-line block scalars, base_path expansion). YAML parse errors are caught at the call sites with a yellow warning, falling back to today's behavior so unrelated commands aren't blocked by a typo. - download: routes typed downloads to the first configured path for the category; preserves the basemodel subdir convention. - list: aggregates files across workspace + extras roots, deduped by realpath, sorted globally; adds a Source column when more than one root is in play; prepends category to Type for extras files. - remove: per-root path-traversal protection; ambiguous --model-names surface candidate paths instead of silently picking one; OSError on resolve() (e.g., circular symlinks) is reported and skipped. - New flags on each subcommand: --extra-model-paths-config PATH (repeatable) and --extra-model-paths/--no-extra-model-paths. Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #439 +/- ##
==========================================
+ Coverage 78.40% 79.19% +0.78%
==========================================
Files 35 36 +1
Lines 4399 4580 +181
==========================================
+ Hits 3449 3627 +178
- Misses 950 953 +3
🚀 New features to boost your workflow:
|
Closes #206.
Summary
comfy_cli/extra_model_paths.pyparses ComfyUI'sextra_model_paths.yamland exposes a pure-functional API. Behavior mirrors upstream'sutils/extra_config.load_extra_path_configand the priority semantics offolder_paths.add_model_folder_pathexactly (legacy aliasesunet/clip, last-is_default-wins, multi-line block scalars,base_pathexpanduser+expandvars).comfy model downloadroutes typed downloads (Civitai/HF) to the first configured path for the category; explicit--relative-pathkeeps full precedence;<basemodel>subdir convention preserved.comfy model listaggregates files across workspace + extras roots, deduped by realpath and assigned to the deepest matching root; adds a Source column when >1 root is present; Type column prepends the canonical category for files coming from extras roots so output stays consistent with workspace listings.comfy model removeenforces per-root path-traversal protection; ambiguous--model-namessurface candidate paths (rather than silently picking one);OSErroronPath.resolve()(e.g., circular symlinks) is reported and skipped instead of crashing.--extra-model-paths-config PATH(repeatable, mirrors upstream's flag of the same name) and--extra-model-paths/--no-extra-model-pathsfor an opt-out.Design
A more detailed design walkthrough including a self-review of every choice is in the original analysis (kept locally, available on request). Key non-obvious decisions:
yaml.YAMLError, lenient on structural errors. Matches both upstream ComfyUI and ComfyUI-Manager (which raise on invalid YAML). Section-level structural problems (None section, non-string category value) are skipped with a warning — strictly more lenient than upstream, which crashes withAttributeErrorin those cases.logging.getLogger(__name__)rather thanfrom comfy_cli import logging. Matches the pattern ofcuda_detect.py(most recent module added) and gives access toexc_info, structured args, etc.model_path_mapentries in this PR. Extending it from 5 entries to ~10 (e.g., addingvae,upscaler) is a separate behavior change — types that today prompt the user would auto-route. Worth a separate, smaller PR.Test plan
extra_model_paths.py(tests/comfy_cli/test_extra_model_paths.py) — covers parser edge cases, multi-section priority, legacy aliases,is_defaultsemantics including the upstream quirk where the lateris_defaultwins for slot 0.download(TestDownloadCommandExtraModelPaths) — baseline (no yaml unchanged), extras routing, explicit--relative-pathprecedence, opt-out flag, mismatched-category fallback,--extra-model-paths-config,is_defaultpriority, HF code path, invalid-yaml warning.list(TestListCommandExtraModelPaths) — baseline preserved, extras files appear, Source column appears only when >1 root, Type column shows<category>/<subdir>, dedup when extras root overlaps workspace, opt-out flag.remove(TestRemoveCommandExtraModelPaths) — extras-path target deletable via abs path, ambiguous--model-nameserrors with candidate list, traversal protection still rejects.., opt-out flag.ruff checkandruff format --checkclean.extra_model_paths.yaml(comfyui:+a111:sections,is_default, multi-line text_encoders entry).pathlib/os.pathops should normalize correctly, but worth confirming the macOS Source column rendering with/private/var/...resolved paths.Out of scope (deferred)
model_path_mapto covervae,upscaler,motionmodule, etc. (separate PR — independent behavior change).--relative-pathexpanduserinconsistency inlist/remove(separate small PR — orthogonal).comfy model pathsdebug subcommand to print the resolved path map.