From 2710d72e07c80328c62260962300fcf62cc0203f Mon Sep 17 00:00:00 2001 From: PONOTECH <119613244+yhayano-ponotech@users.noreply.github.com> Date: Sat, 4 Jan 2025 09:02:45 +0900 Subject: [PATCH] Fix NameError in get_custom_nodes_paths method (#1393) This commit addresses the NameError that occurs in the get_custom_nodes_paths method of the Ctx class. The error was caused by the folder_paths module not being properly imported or accessible within the static method. The fix involves the following changes: 1. Add a class variable folder_paths to the Ctx class. 2. Import the folder_paths module in the __init__ method using importlib. 3. Update the get_custom_nodes_paths method to use the class variable. 4. Add error handling to gracefully handle cases where the folder_paths module cannot be imported. These changes ensure that the folder_paths module is properly imported and accessible within the Ctx class, resolving the NameError and improving the overall stability of the ComfyUI-Manager CLI tool. Co-authored-by: yhayano-ponotech --- cm-cli.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cm-cli.py b/cm-cli.py index 9689215a..8c227414 100644 --- a/cm-cli.py +++ b/cm-cli.py @@ -12,6 +12,7 @@ from rich import print from typing_extensions import List, Annotated import re import git +import importlib sys.path.append(os.path.dirname(__file__)) @@ -88,12 +89,20 @@ read_downgrade_blacklist() # This is a preparation step for manager_core class Ctx: + folder_paths = None + def __init__(self): self.channel = 'default' self.no_deps = False self.mode = 'cache' self.user_directory = None self.custom_nodes_paths = [os.path.join(core.comfy_path, 'custom_nodes')] + + if Ctx.folder_paths is None: + try: + Ctx.folder_paths = importlib.import_module('folder_paths') + except ImportError: + print("Warning: Unable to import folder_paths module") def set_channel_mode(self, channel, mode): if mode is not None: @@ -145,7 +154,10 @@ class Ctx: @staticmethod def get_custom_nodes_paths(): - return folder_paths.get_folder_paths('custom_nodes') + if Ctx.folder_paths is None: + print("Error: folder_paths module is not available") + return [] + return Ctx.folder_paths.get_folder_paths('custom_nodes') cmd_ctx = Ctx()