From 7ebd45350d1ba8d022dcff1ca29617c5541aa708 Mon Sep 17 00:00:00 2001 From: Peyton DeNiro <25550995+pydn@users.noreply.github.com> Date: Sun, 10 May 2026 09:58:06 -0500 Subject: [PATCH] fix: filter comfy/ subdirectory from sys.path before loading server.py nodes.py inserts the comfy/ subdirectory into sys.path, which shadows the top-level utils/ package (comfy/utils.py vs utils/__init__.py). This breaks server.py's import chain when app.frontend_management does 'from utils.install_util import ...'. Filter out the comfy/ subdirectory temporarily before loading server.py, then restore it immediately after. Use list comprehension instead of sys.path.remove to satisfy the gap-window test assertion. --- comfyui_to_python/node_runtime.py | 12 ++++++++++++ tests/runtime/generated/upscale-model-loader.py | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/comfyui_to_python/node_runtime.py b/comfyui_to_python/node_runtime.py index d4782f8..e9127ff 100644 --- a/comfyui_to_python/node_runtime.py +++ b/comfyui_to_python/node_runtime.py @@ -258,8 +258,20 @@ def import_custom_nodes() -> None: "execution", os.path.join(comfyui_path, "execution.py") ) nodes_mod = _load_module("nodes", os.path.join(comfyui_path, "nodes.py")) + + # nodes.py inserts comfy/ subdirectory into sys.path, which shadows the + # top-level utils/ package (comfy/utils.py vs utils/). This breaks + # server.py → app.frontend_management → from utils.install_util import ... + # Filter it out temporarily so server.py loads cleanly. + comfy_subdir = os.path.join(comfyui_path, "comfy") + original_sys_path = list(sys.path) + sys.path[:] = [p for p in sys.path if p != comfy_subdir] + server_mod = _load_module("server", os.path.join(comfyui_path, "server.py")) + # Restore sys.path so nodes and other modules that need comfy/ still work + sys.path[:] = original_sys_path + if execution_mod is None or server_mod is None: log.debug( "import_custom_nodes: could not load execution/server modules. " diff --git a/tests/runtime/generated/upscale-model-loader.py b/tests/runtime/generated/upscale-model-loader.py index 6e04ee5..642d7aa 100644 --- a/tests/runtime/generated/upscale-model-loader.py +++ b/tests/runtime/generated/upscale-model-loader.py @@ -268,8 +268,20 @@ def import_custom_nodes() -> None: "execution", os.path.join(comfyui_path, "execution.py") ) nodes_mod = _load_module("nodes", os.path.join(comfyui_path, "nodes.py")) + + # nodes.py inserts comfy/ subdirectory into sys.path, which shadows the + # top-level utils/ package (comfy/utils.py vs utils/). This breaks + # server.py → app.frontend_management → from utils.install_util import ... + # Filter it out temporarily so server.py loads cleanly. + comfy_subdir = os.path.join(comfyui_path, "comfy") + original_sys_path = list(sys.path) + sys.path[:] = [p for p in sys.path if p != comfy_subdir] + server_mod = _load_module("server", os.path.join(comfyui_path, "server.py")) + # Restore sys.path so nodes and other modules that need comfy/ still work + sys.path[:] = original_sys_path + if execution_mod is None or server_mod is None: log.debug( "import_custom_nodes: could not load execution/server modules. "