-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path__init__.py
More file actions
49 lines (40 loc) · 1.64 KB
/
__init__.py
File metadata and controls
49 lines (40 loc) · 1.64 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
from pathlib import Path
import sys
import os
import importlib.util
# Add module directory to Python path
current_dir = Path(__file__).parent
if str(current_dir) not in sys.path:
sys.modules[__name__] = sys.modules.get(__name__, type(__name__, (), {}))
sys.path.insert(0, str(current_dir))
# Initialize mappings
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
WEB_DIRECTORY = "./web"
def load_nodes():
"""Automatically discover and load node definitions"""
for file in current_dir.glob("*.py"):
if file.stem == "__init__":
continue
try:
# Import module
spec = importlib.util.spec_from_file_location(file.stem, file)
if spec and spec.loader:
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
# Update mappings
if hasattr(module, "NODE_CLASS_MAPPINGS"):
NODE_CLASS_MAPPINGS.update(module.NODE_CLASS_MAPPINGS)
if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS"):
NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS)
# Initialize paths if available
if hasattr(module, "Paths") and hasattr(module.Paths, "LLM_DIR"):
os.makedirs(module.Paths.LLM_DIR, exist_ok=True)
except Exception as e:
print(f"Error loading {file.name}: {str(e)}")
# Load all nodes
load_nodes()
__all__ = [
"NODE_CLASS_MAPPINGS",
"NODE_DISPLAY_NAME_MAPPINGS"
]