Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
82 lines (68 loc) · 2.85 KB
/
Copy path__init__.py
File metadata and controls
82 lines (68 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import importlib.util
import os
import sys
# --- Report missing dependencies (installed from requirements.txt by ComfyUI-Manager / comfy-cli) ---
_REQUIRED_PACKAGES = {
"cv2": "opencv-python",
"scipy": "scipy",
"av": "av",
"pydantic": "pydantic",
}
_missing = [pip for mod, pip in _REQUIRED_PACKAGES.items() if importlib.util.find_spec(mod) is None]
if _missing:
print(
f"[WaveSpeed] Missing dependencies: {', '.join(_missing)}. "
f"Install this node's requirements.txt into ComfyUI's Python ({sys.executable}); see the README."
)
# Import API endpoints to register routes
try:
from .py import wavespeed_api_endpoints
print("[WaveSpeed] API endpoints loaded successfully")
except Exception as e:
print(f"[WaveSpeed] Failed to load API endpoints: {e}")
import traceback
traceback.print_exc()
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
# Files that are utility modules (no ComfyUI nodes), skip them during node discovery
_SKIP_NODE_FILES = {"wavespeed_api_endpoints", "wavespeed_catalog", "wavespeed_config"}
def get_ext_dir(subpath=None, mkdir=False):
dir = os.path.dirname(__file__)
if subpath is not None:
dir = os.path.join(dir, subpath)
dir = os.path.abspath(dir)
if mkdir and not os.path.exists(dir):
os.makedirs(dir)
return dir
def serialize(obj):
if isinstance(obj, (str, int, float, bool, list, dict, type(None))):
return obj
return str(obj)
py = get_ext_dir("py")
files = os.listdir(py)
all_nodes = {}
for file in files:
if not file.endswith(".py"):
continue
name = os.path.splitext(file)[0]
if name in _SKIP_NODE_FILES:
continue
try:
imported_module = importlib.import_module(".py.{}".format(name), __name__)
try:
node_mappings = imported_module.NODE_CLASS_MAPPINGS
NODE_CLASS_MAPPINGS = {**NODE_CLASS_MAPPINGS, **node_mappings}
NODE_DISPLAY_NAME_MAPPINGS = {**NODE_DISPLAY_NAME_MAPPINGS, **imported_module.NODE_DISPLAY_NAME_MAPPINGS}
serialized_CLASS_MAPPINGS = {k: serialize(v) for k, v in node_mappings.items()}
serialized_DISPLAY_NAME_MAPPINGS = {k: serialize(v) for k, v in imported_module.NODE_DISPLAY_NAME_MAPPINGS.items()}
all_nodes[file]={"NODE_CLASS_MAPPINGS": serialized_CLASS_MAPPINGS, "NODE_DISPLAY_NAME_MAPPINGS": serialized_DISPLAY_NAME_MAPPINGS}
except AttributeError:
print(f"[WaveSpeed] Skipping {file}: no NODE_CLASS_MAPPINGS (not a node module)")
except Exception as e:
print(f"[WaveSpeed] Warning: Could not load node mappings from {file}: {e}")
except Exception as e:
print(f"[WaveSpeed] Error importing {file}: {e}")
import traceback
traceback.print_exc()
WEB_DIRECTORY = "./web"
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]