Skip to content

Commit 68bb885

Browse files
authored
add 'is_default' to model paths config (comfyanonymous#4979)
* add 'is_default' to model paths config including impl and doc in example file * update weirdly overspecific test expectations * oh there's two * sigh
1 parent ad66f7c commit 68bb885

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

extra_model_paths.yaml.example

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ a111:
2525

2626
#comfyui:
2727
# base_path: path/to/comfyui/
28+
# # You can use is_default to mark that these folders should be listed first, and used as the default dirs for eg downloads
29+
# #is_default: true
2830
# checkpoints: models/checkpoints/
2931
# clip: models/clip/
3032
# clip_vision: models/clip_vision/

folder_paths.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,14 @@ def exists_annotated_filepath(name) -> bool:
195195
return os.path.exists(filepath)
196196

197197

198-
def add_model_folder_path(folder_name: str, full_folder_path: str) -> None:
198+
def add_model_folder_path(folder_name: str, full_folder_path: str, is_default: bool = False) -> None:
199199
global folder_names_and_paths
200200
folder_name = map_legacy(folder_name)
201201
if folder_name in folder_names_and_paths:
202-
folder_names_and_paths[folder_name][0].append(full_folder_path)
202+
if is_default:
203+
folder_names_and_paths[folder_name][0].insert(0, full_folder_path)
204+
else:
205+
folder_names_and_paths[folder_name][0].append(full_folder_path)
203206
else:
204207
folder_names_and_paths[folder_name] = ([full_folder_path], set())
205208

tests-unit/utils/extra_config_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_load_extra_model_paths_expands_userpath(
7171
load_extra_path_config(dummy_yaml_file_name)
7272

7373
expected_calls = [
74-
('checkpoints', os.path.join(mock_expanded_home, 'App', 'subfolder1')),
74+
('checkpoints', os.path.join(mock_expanded_home, 'App', 'subfolder1'), False),
7575
]
7676

7777
assert mock_add_model_folder_path.call_count == len(expected_calls)
@@ -111,7 +111,7 @@ def test_load_extra_model_paths_expands_appdata(
111111

112112
expected_base_path = 'C:/Users/TestUser/AppData/Roaming/ComfyUI'
113113
expected_calls = [
114-
('checkpoints', os.path.join(expected_base_path, 'models/checkpoints')),
114+
('checkpoints', os.path.join(expected_base_path, 'models/checkpoints'), False),
115115
]
116116

117117
assert mock_add_model_folder_path.call_count == len(expected_calls)

utils/extra_config.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def load_extra_path_config(yaml_path):
1414
if "base_path" in conf:
1515
base_path = conf.pop("base_path")
1616
base_path = os.path.expandvars(os.path.expanduser(base_path))
17+
is_default = False
18+
if "is_default" in conf:
19+
is_default = conf.pop("is_default")
1720
for x in conf:
1821
for y in conf[x].split("\n"):
1922
if len(y) == 0:
@@ -22,4 +25,4 @@ def load_extra_path_config(yaml_path):
2225
if base_path is not None:
2326
full_path = os.path.join(base_path, full_path)
2427
logging.info("Adding extra search path {} {}".format(x, full_path))
25-
folder_paths.add_model_folder_path(x, full_path)
28+
folder_paths.add_model_folder_path(x, full_path, is_default)

0 commit comments

Comments
 (0)