mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-16 00:12:33 +08:00
Move get_comfy_models_folders to path_utils.py to avoid late import
Amp-Thread-ID: https://ampcode.com/threads/T-019c2510-33fa-7199-ae4b-bc31102277a7 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
parent
2eb100adf9
commit
e987bd268f
@ -7,6 +7,21 @@ import folder_paths
|
|||||||
from app.assets.helpers import normalize_tags
|
from app.assets.helpers import normalize_tags
|
||||||
|
|
||||||
|
|
||||||
|
def get_comfy_models_folders() -> list[tuple[str, list[str]]]:
|
||||||
|
"""Build a list of (folder_name, base_paths[]) categories that are configured for model locations.
|
||||||
|
|
||||||
|
We trust `folder_paths.folder_names_and_paths` and include a category if
|
||||||
|
*any* of its base paths lies under the Comfy `models_dir`.
|
||||||
|
"""
|
||||||
|
targets: list[tuple[str, list[str]]] = []
|
||||||
|
models_root = os.path.abspath(folder_paths.models_dir)
|
||||||
|
for name, values in folder_paths.folder_names_and_paths.items():
|
||||||
|
paths, _exts = values[0], values[1] # NOTE: this prevents nodepacks that hackily edit folder_... from breaking ComfyUI
|
||||||
|
if any(os.path.abspath(p).startswith(models_root + os.sep) for p in paths):
|
||||||
|
targets.append((name, paths))
|
||||||
|
return targets
|
||||||
|
|
||||||
|
|
||||||
def resolve_destination_from_tags(tags: list[str]) -> tuple[str, list[str]]:
|
def resolve_destination_from_tags(tags: list[str]) -> tuple[str, list[str]]:
|
||||||
"""Validates and maps tags -> (base_dir, subdirs_for_fs)"""
|
"""Validates and maps tags -> (base_dir, subdirs_for_fs)"""
|
||||||
root = tags[0]
|
root = tags[0]
|
||||||
@ -84,8 +99,6 @@ def get_relative_to_root_category_path_of_asset(file_path: str) -> tuple[Literal
|
|||||||
Raises:
|
Raises:
|
||||||
ValueError: if the path does not belong to input, output, or configured model bases.
|
ValueError: if the path does not belong to input, output, or configured model bases.
|
||||||
"""
|
"""
|
||||||
from app.assets.services.scanner import get_comfy_models_folders
|
|
||||||
|
|
||||||
fp_abs = os.path.abspath(file_path)
|
fp_abs = os.path.abspath(file_path)
|
||||||
|
|
||||||
def _is_within(child: str, parent: str) -> bool:
|
def _is_within(child: str, parent: str) -> bool:
|
||||||
|
|||||||
@ -27,7 +27,11 @@ from app.assets.database.queries import (
|
|||||||
bulk_insert_tags_and_meta,
|
bulk_insert_tags_and_meta,
|
||||||
)
|
)
|
||||||
from app.assets.helpers import utcnow
|
from app.assets.helpers import utcnow
|
||||||
from app.assets.services.path_utils import compute_relative_filename, get_name_and_tags_from_asset_path
|
from app.assets.services.path_utils import (
|
||||||
|
compute_relative_filename,
|
||||||
|
get_comfy_models_folders,
|
||||||
|
get_name_and_tags_from_asset_path,
|
||||||
|
)
|
||||||
from app.database.db import create_session, dependencies_available
|
from app.database.db import create_session, dependencies_available
|
||||||
|
|
||||||
|
|
||||||
@ -61,21 +65,6 @@ def list_tree(base_dir: str) -> list[str]:
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def get_comfy_models_folders() -> list[tuple[str, list[str]]]:
|
|
||||||
"""Build a list of (folder_name, base_paths[]) categories that are configured for model locations.
|
|
||||||
|
|
||||||
We trust `folder_paths.folder_names_and_paths` and include a category if
|
|
||||||
*any* of its base paths lies under the Comfy `models_dir`.
|
|
||||||
"""
|
|
||||||
targets: list[tuple[str, list[str]]] = []
|
|
||||||
models_root = os.path.abspath(folder_paths.models_dir)
|
|
||||||
for name, values in folder_paths.folder_names_and_paths.items():
|
|
||||||
paths, _exts = values[0], values[1] # NOTE: this prevents nodepacks that hackily edit folder_... from breaking ComfyUI
|
|
||||||
if any(os.path.abspath(p).startswith(models_root + os.sep) for p in paths):
|
|
||||||
targets.append((name, paths))
|
|
||||||
return targets
|
|
||||||
|
|
||||||
|
|
||||||
def prefixes_for_root(root: RootType) -> list[str]:
|
def prefixes_for_root(root: RootType) -> list[str]:
|
||||||
if root == "models":
|
if root == "models":
|
||||||
bases: list[str] = []
|
bases: list[str] = []
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user