@@ -28,62 +28,51 @@ def import_custom_nodes() -> None:
28
28
# Initializing custom nodes
29
29
init_custom_nodes ()
30
30
31
- def add_comfyui_directory_to_sys_path ( ) -> None :
31
+ def find_path ( name : str , path : str = None ) -> Union [ Path , None ] :
32
32
"""
33
- Recursively looks at parent folders starting from the current working directory until it finds 'ComfyUI'.
34
- Once found, the directory is added to sys.path .
33
+ Recursively looks at parent folders starting from the given path until it finds the given name.
34
+ Returns the path as a Path object if found, or None otherwise .
35
35
"""
36
- start_path = os .getcwd () # Get the current working directory
36
+ # If no path is given, use the current working directory
37
+ if path is None :
38
+ path = os .getcwd ()
39
+
40
+ # Check if the current directory contains the name
41
+ if name in os .listdir (path ):
42
+ path_name = os .path .join (path , name )
43
+ print (f"{ name } found: { path_name } " )
44
+ return Path (path_name )
37
45
38
- def search_directory (path : str ) -> None :
39
- # Check if the current directory contains 'ComfyUI'
40
- if 'ComfyUI' in os .listdir (path ):
41
- directory_path = os .path .join (path , 'ComfyUI' )
42
- sys .path .append (directory_path )
43
- print (f"ComfyUI found and added to sys.path: { directory_path } " )
46
+ # Get the parent directory
47
+ parent_directory = os .path .dirname (path )
44
48
45
- # Get the parent directory
46
- parent_directory = os .path .dirname (path )
49
+ # If the parent directory is the same as the current directory, we've reached the root and stop the search
50
+ if parent_directory == path :
51
+ return None
47
52
48
- # If the parent directory is the same as the current directory, we've reached the root and stop the search
49
- if parent_directory == path :
50
- return
53
+ # Recursively call the function with the parent directory
54
+ return find_path (name , parent_directory )
51
55
52
- # Recursively call the function with the parent directory
53
- search_directory (parent_directory )
54
56
55
- # Start the search from the current working directory
56
- search_directory (start_path )
57
+ def add_comfyui_directory_to_sys_path () -> None :
58
+ """
59
+ Add 'ComfyUI' to the sys.path
60
+ """
61
+ comfyui_path = find_path ('ComfyUI' )
62
+ if comfyui_path is not None and os .path .isdir (comfyui_path ):
63
+ sys .path .append (comfyui_path )
64
+ print (f"'{ comfyui_path } ' added to sys.path" )
57
65
58
66
def add_extra_model_paths () -> Path :
59
67
"""
60
68
Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path.
61
69
"""
62
- from pathlib import Path
63
70
from main import load_extra_path_config
64
71
65
- def find_config_file (path : str , name : str = "extra_model_paths.yaml" ) -> Path :
66
- # Check if the current directory contains the file
67
- if name in os .listdir (path ):
68
- directory_path = os .path .join (path , name )
69
- print (f"{ name } found: { directory_path } " )
70
- return Path (directory_path )
71
-
72
- # Get the parent directory
73
- parent_directory = os .path .dirname (path )
74
-
75
- # If the parent directory is the same as the current directory, we've reached the root and stop the search
76
- if parent_directory == path :
77
- return
78
-
79
- # Recursively call the function with the parent directory
80
- return find_config_file (parent_directory )
81
-
82
- start_path = os .getcwd () # Get the current working directory
83
- file = find_config_file (start_path )
72
+ extra_model_paths = find_path ("extra_model_paths.yaml" )
84
73
85
- if os . path . isfile ( file ) :
86
- load_extra_path_config (file )
74
+ if extra_model_paths is not None :
75
+ load_extra_path_config (extra_model_paths )
87
76
else :
88
77
print ("Could not find the extra_model_paths config file." )
89
78
0 commit comments