Skip to content

Commit 27f7a84

Browse files
author
Peyton
committed
Clean up load extra models code.
1 parent ffe21d2 commit 27f7a84

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

comfyui_to_python.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import glob
33
import inspect
44
import json
5-
import logging
65
import os
76
import random
87
import sys
@@ -11,20 +10,13 @@
1110

1211
import black
1312

14-
sys.path.append('../')
1513

16-
try:
17-
from utils import import_custom_nodes, find_path, add_comfyui_directory_to_sys_path, add_extra_model_paths, get_value_at_index
18-
except ImportError:
19-
sys.path.append('.')
20-
from utils import import_custom_nodes, find_path, add_comfyui_directory_to_sys_path, add_extra_model_paths, get_value_at_index
14+
from utils import import_custom_nodes, find_path, add_comfyui_directory_to_sys_path, add_extra_model_paths, get_value_at_index
2115

16+
sys.path.append('../')
2217
from nodes import NODE_CLASS_MAPPINGS
2318

2419

25-
logging.basicConfig(level=logging.INFO)
26-
27-
2820
class FileHandler:
2921
"""Handles reading and writing files.
3022
@@ -311,10 +303,10 @@ def assemble_python_code(self, import_statements: set, speical_functions_code: L
311303
"""
312304
# Get the source code of the utils functions as a string
313305
func_strings = []
314-
for func in [find_path, add_comfyui_directory_to_sys_path, add_extra_model_paths, get_value_at_index]:
306+
for func in [get_value_at_index, find_path, add_comfyui_directory_to_sys_path, add_extra_model_paths]:
315307
func_strings.append(f'\n{inspect.getsource(func)}')
316308
# Define static import statements required for the script
317-
static_imports = ['import os', 'import random', 'from pathlib import Path', 'import sys', 'from typing import Sequence, Mapping, Any, Union',
309+
static_imports = ['import os', 'import random', 'import sys', 'from typing import Sequence, Mapping, Any, Union',
318310
'import torch'] + func_strings + ['\n\nadd_comfyui_directory_to_sys_path()\nadd_extra_model_paths()\n']
319311
# Check if custom nodes should be included
320312
if custom_nodes:

utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
from typing import Sequence, Mapping, Any, Union
3-
from pathlib import Path
43
import sys
54

65
sys.path.append('../')
@@ -28,7 +27,8 @@ def import_custom_nodes() -> None:
2827
# Initializing custom nodes
2928
init_custom_nodes()
3029

31-
def find_path(name: str, path: str = None) -> Union[Path, None]:
30+
31+
def find_path(name: str, path: str = None) -> str:
3232
"""
3333
Recursively looks at parent folders starting from the given path until it finds the given name.
3434
Returns the path as a Path object if found, or None otherwise.
@@ -41,7 +41,7 @@ def find_path(name: str, path: str = None) -> Union[Path, None]:
4141
if name in os.listdir(path):
4242
path_name = os.path.join(path, name)
4343
print(f"{name} found: {path_name}")
44-
return Path(path_name)
44+
return path_name
4545

4646
# Get the parent directory
4747
parent_directory = os.path.dirname(path)
@@ -63,7 +63,8 @@ def add_comfyui_directory_to_sys_path() -> None:
6363
sys.path.append(comfyui_path)
6464
print(f"'{comfyui_path}' added to sys.path")
6565

66-
def add_extra_model_paths() -> Path:
66+
67+
def add_extra_model_paths() -> None:
6768
"""
6869
Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path.
6970
"""

0 commit comments

Comments
 (0)