Better way for add models
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 158
Description
### Feature Idea
I want to modify this file: **extra_config.py,** then it will be works better. I already tested on my windows, it worked.
ComfyUI_windows_portable\ComfyUI\utils\extra_config.py
### Existing Solutions
```
import os
import yaml
import folder_paths
import logging
def load_extra_path_config(yaml_path):
with open(yaml_path, 'r', encoding='utf-8') as stream:
config = yaml.safe_load(stream)
yaml_dir = os.path.dirname(os.path.abspath(yaml_path))
for c in config:
conf = config[c]
if conf is None:
continue
base_path = None
if "base_path" in conf:
base_path = conf.pop("base_path")
base_path = os.path.expandvars(os.path.expanduser(base_path))
if not os.path.isabs(base_path):
base_path = os.path.abspath(os.path.join(yaml_dir, base_path))
is_default = False
if "is_default" in conf:
is_default = conf.pop("is_default")
# 1. 处理你手动写的路径 Deal with your manual path(Like checkpoints: models/checkpoints)
for x in conf:
for y in conf[x].split("\n"):
if len(y.strip()) == 0:
continue
full_path = y.strip()
if base_path:
full_path = os.path.join(base_path, full_path)
elif not os.path.isabs(full_path):
full_path = os.path.abspath(os.path.join(yaml_dir, full_path))
normalized_path = os.path.normpath(full_path)
logging.info(f"Adding extra search path '{x}' -> '{normalized_path}'")
folder_paths.add_model_folder_path(x, normalized_path, is_default)
# 2. 自动添加 Auto add: base_path/models/* 中所有文件夹 all folders(自动识别路径 Auto find path)
if base_path is not None:
auto_model_root = os.path.join(base_path, "models")
if os.path.exists(auto_model_root) and os.path.isdir(auto_model_root):
folder_list = [f for f in os.listdir(auto_model_root) if os.path.isdir(os.path.join(auto_model_root, f))]
for folder_name in folder_list:
folder_path = os.path.join(auto_model_root, folder_name)
try:
logging.info(f"Auto-detecting and adding folder '{folder_name}' -> '{folder_path}'")
folder_paths.add_model_folder_path(folder_name, folder_path, is_default)
except Exception as e:
logging.warning(f"Failed to add auto-detected folder '{folder_name}': {e}")
```
and then , I just need add **extra_model_paths.yaml** path like this :
### Other
```
comfyui:
base_path: D:\
# actually I just need one line, and it will work
# checkpoints: models/checkpoints/
# clip: models/clip/
# clip_vision: models/clip_vision/
# configs: models/configs/
# controlnet: models/controlnet/
# embeddings: models/embeddings/
# loras: models/loras/
# upscale_models: models/upscale_models/
# vae: models/vae/
# llm: models/LLM/
other_ui:
base_path: H:\
# my all models is here:
is_default: true
# checkpoints: models/checkpoints
# gligen: models/gligen
# custom_nodes: path/custom_nodes
```
Actually I just need one line, and it will work.
Hope it will be helpful.
Contributor guide
Assessment
This issue has not been assessed yet.