From 87792fe33d555668d89ed20cdbc4292b0dbefaa0 Mon Sep 17 00:00:00 2001 From: Tasha Upchurch Date: Mon, 26 Jun 2023 17:47:53 -0400 Subject: [PATCH] Import classes directly from file instead of using importlib fix for bug that was allowing importlib to find addons from other installations. --- __init__.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index c565754..c37edaf 100644 --- a/__init__.py +++ b/__init__.py @@ -44,11 +44,22 @@ for module_file in os.listdir(package_dir): if module_file.endswith('.py') and not module_file.startswith('__'): module_name = package_name + '.' + module_file[:-3] # Removing .py extension try: - module = importlib.import_module(module_name) - for class_name in dir(module): - class_obj = getattr(module, class_name) - if isinstance(class_obj, type) and hasattr(class_obj, 'INPUT_TYPES'): # Checking if it's a class and has INPUT_TYPES attribute + # import directly from the file + full_path = os.path.join(package_dir, module_file) + with open(full_path, 'r') as f: + code = f.read() + exec(code, globals(), locals()) + for class_name in dir(): + class_obj = locals()[class_name] + if isinstance(class_obj, type) and hasattr(class_obj, 'INPUT_TYPES'): NODE_CLASS_MAPPINGS[class_name] = class_obj + + + #module = importlib.import_module(module_name) + #for class_name in dir(module): + # class_obj = getattr(module, class_name) + # if isinstance(class_obj, type) and hasattr(class_obj, 'INPUT_TYPES'): # Checking if it's a class and has INPUT_TYPES attribute + # NODE_CLASS_MAPPINGS[class_name] = class_obj except ImportError: if not use_generic_nodes: print(f"Failed to import {module_name}, it may require comfy.samplers. Skipping...")