-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
49 lines (34 loc) · 1.17 KB
/
__init__.py
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
import importlib
import os
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
# Main nodes for all users
NODE_MODULES = [
".nodes"
]
def load_nodes(module_name: str):
global NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
module = importlib.import_module(module_name, package=__name__)
NODE_CLASS_MAPPINGS = {
**NODE_CLASS_MAPPINGS,
**module.NODE_CLASS_MAPPINGS,
}
NODE_DISPLAY_NAME_MAPPINGS = {
**NODE_DISPLAY_NAME_MAPPINGS,
**module.NODE_DISPLAY_NAME_MAPPINGS,
}
def write_nodes_list(module_names: list[str]):
this_dir = os.path.dirname(os.path.abspath(__file__))
path = os.path.join(this_dir, "nodes.log")
lines = []
for module_name in module_names:
module = importlib.import_module(module_name, package=__name__)
lines.append(module_name.strip("."))
for identifier, display_name in module.NODE_DISPLAY_NAME_MAPPINGS.items():
lines.append(f" {identifier}: {display_name}")
lines.append("")
lines = "\n".join(lines)
with open(path, "w", encoding="utf8") as f:
f.write(lines)
for module_name in NODE_MODULES:
load_nodes(module_name)