Skip to content

Commit

Permalink
Normalize extra_model_config.yaml paths to prevent duplicates. (#6885)
Browse files Browse the repository at this point in the history
* Normalize extra_model_config.yaml paths before adding.

* Fix tests.

* Fix tests.
  • Loading branch information
robinjhuang authored Feb 20, 2025
1 parent c5be423 commit 29d4384
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions tests-unit/utils/extra_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_load_extra_model_paths_expands_appdata(
else:
expected_base_path = '/Users/TestUser/AppData/Roaming/ComfyUI'
expected_calls = [
('checkpoints', os.path.join(expected_base_path, 'models/checkpoints'), False),
('checkpoints', os.path.normpath(os.path.join(expected_base_path, 'models/checkpoints')), False),
]

assert mock_add_model_folder_path.call_count == len(expected_calls)
Expand Down Expand Up @@ -197,8 +197,8 @@ def fake_dirname(path):

load_extra_path_config(dummy_yaml_name)

expected_checkpoints = os.path.abspath(os.path.join(str(tmp_path), sub_folder, "checkpoints"))
expected_some_value = os.path.abspath(os.path.join(str(tmp_path), sub_folder, "some_value"))
expected_checkpoints = os.path.abspath(os.path.join(str(tmp_path), "my_rel_base", "checkpoints"))
expected_some_value = os.path.abspath(os.path.join(str(tmp_path), "my_rel_base", "some_value"))

actual_paths = folder_paths.folder_names_and_paths["checkpoints"][0]
assert len(actual_paths) == 1, "Should have one path added for 'checkpoints'."
Expand Down
5 changes: 3 additions & 2 deletions utils/extra_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ def load_extra_path_config(yaml_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, y))
logging.info("Adding extra search path {} {}".format(x, full_path))
folder_paths.add_model_folder_path(x, full_path, is_default)
normalized_path = os.path.normpath(full_path)
logging.info("Adding extra search path {} {}".format(x, normalized_path))
folder_paths.add_model_folder_path(x, normalized_path, is_default)

0 comments on commit 29d4384

Please sign in to comment.