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:
Luke Mino-Altherr 2026-02-03 12:02:41 -08:00
parent 2eb100adf9
commit e987bd268f
2 changed files with 20 additions and 18 deletions

View File

@ -7,6 +7,21 @@ import folder_paths
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]]:
"""Validates and maps tags -> (base_dir, subdirs_for_fs)"""
root = tags[0]
@ -84,8 +99,6 @@ def get_relative_to_root_category_path_of_asset(file_path: str) -> tuple[Literal
Raises:
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)
def _is_within(child: str, parent: str) -> bool:

View File

@ -27,7 +27,11 @@ from app.assets.database.queries import (
bulk_insert_tags_and_meta,
)
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
@ -61,21 +65,6 @@ def list_tree(base_dir: str) -> list[str]:
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]:
if root == "models":
bases: list[str] = []