added EXTENSION_MODULES_LOADED guard set to prevent double loading of extensions

This commit is contained in:
telamonian 2024-06-01 02:37:45 -04:00
parent 968595b123
commit 0d2b1eb95b
2 changed files with 28 additions and 1 deletions

4
.gitignore vendored
View File

@ -1,5 +1,6 @@
__pycache__/
*.py[cod]
*.egg-info/
/output/
/input/
!/input/example.png
@ -16,3 +17,6 @@ venv/
!/web/extensions/core/
/tests-ui/data/object_info.json
/user/
.history/
.vscode/
*.code-workspace

View File

@ -1861,11 +1861,20 @@ NODE_DISPLAY_NAME_MAPPINGS = {
EXTENSION_WEB_DIRS = {}
EXTENSION_MODULES_LOADED = set()
def load_custom_node(module_path, ignore=set()):
module_name = os.path.basename(module_path)
if os.path.isfile(module_path):
sp = os.path.splitext(module_path)
module_name = sp[0]
if module_name in EXTENSION_MODULES_LOADED:
logging.warning(f"Skip {module_path} module for custom nodes due to it already being loaded.")
return False
else:
EXTENSION_MODULES_LOADED.add(module_name)
try:
logging.debug("Trying to load custom node {}".format(module_path))
if os.path.isfile(module_path):
@ -1928,16 +1937,30 @@ def load_custom_nodes():
def load_custom_nodes_entry_points():
base_node_names = set(NODE_CLASS_MAPPINGS.keys())
extension_modules = set()
for ep in entry_points(group="comfyui.node_class_mappings"):
if ep.module in EXTENSION_MODULES_LOADED:
logging.warning(f"Skip {ep.module} module for node_class_mappings entry point due to it already being loaded.")
continue
class_mapping = ep.load()
for name in class_mapping:
if name not in base_node_names:
NODE_CLASS_MAPPINGS[name] = class_mapping[name]
extension_modules.add(ep.module)
for ep in entry_points(group="comfyui.node_display_name_mappings"):
if ep.module in EXTENSION_MODULES_LOADED:
logging.warning(f"Skip {ep.module} module for node_display_name_mappings entry point due to it already being loaded.")
continue
display_name_mapping = ep.load()
NODE_DISPLAY_NAME_MAPPINGS.update(display_name_mapping)
extension_modules.add(ep.module)
# delay adding new module names to the guard set until after all possible entry_points are loaded
EXTENSION_MODULES_LOADED |= extension_modules
def init_custom_nodes():
extras_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras")