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 <yhayano.biz@gmail.com>
This commit is contained in:
PONOTECH 2025-01-04 09:02:45 +09:00 committed by GitHub
parent c3a1401960
commit 2710d72e07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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()