refactor: unify standalone mode check using environment variable

This commit is contained in:
Will Miao
2025-09-21 22:45:11 +08:00
parent 7e20f738fb
commit fec85bcc08
8 changed files with 15 additions and 12 deletions

View File

@@ -3,12 +3,11 @@ import platform
import folder_paths # type: ignore
from typing import List
import logging
import sys
import json
import urllib.parse
# Check if running in standalone mode
standalone_mode = 'nodes' not in sys.modules
# Use an environment variable to control standalone mode
standalone_mode = os.environ.get("HF_HUB_DISABLE_TELEMETRY", "0") == "0"
logger = logging.getLogger(__name__)

View File

@@ -1,9 +1,7 @@
import os
import importlib
import sys
# Check if running in standalone mode
standalone_mode = 'nodes' not in sys.modules
standalone_mode = os.environ.get("HF_HUB_DISABLE_TELEMETRY", "0") == "0"
if not standalone_mode:
from .metadata_hook import MetadataHook

View File

@@ -1,9 +1,9 @@
import json
import sys
import os
from .constants import IMAGES
# Check if running in standalone mode
standalone_mode = 'nodes' not in sys.modules
standalone_mode = os.environ.get("HF_HUB_DISABLE_TELEMETRY", "0") == "0"
from .constants import MODELS, PROMPTS, SAMPLING, LORAS, SIZE, IS_SAMPLER

View File

@@ -18,7 +18,7 @@ from ..services.websocket_manager import ws_manager
from ..services.downloader import get_downloader
logger = logging.getLogger(__name__)
standalone_mode = 'nodes' not in sys.modules
standalone_mode = os.environ.get("HF_HUB_DISABLE_TELEMETRY", "0") == "0"
# Node registry for tracking active workflow nodes
class NodeRegistry:

View File

@@ -21,7 +21,7 @@ from ..services.server_i18n import server_i18n
from ..config import config
# Check if running in standalone mode
standalone_mode = 'nodes' not in sys.modules
standalone_mode = os.environ.get("HF_HUB_DISABLE_TELEMETRY", "0") == "0"
from ..services.service_registry import ServiceRegistry # Add ServiceRegistry import
from ..services.downloader import get_downloader

View File

@@ -1,6 +1,5 @@
import os
import json
import sys
import time
import asyncio
import logging
@@ -12,7 +11,7 @@ from ..config import config
from ..services.service_registry import ServiceRegistry
# Check if running in standalone mode
standalone_mode = 'nodes' not in sys.modules
standalone_mode = os.environ.get("HF_HUB_DISABLE_TELEMETRY", "0") == "0"
if not standalone_mode:
from ..metadata_collector.metadata_registry import MetadataRegistry

View File

@@ -10,6 +10,10 @@ import sys
import os
from pathlib import Path
# Set environment variable to indicate standalone mode
# HF_HUB_DISABLE_TELEMETRY is from ComfyUI main.py
standalone_mode = os.environ.get("HF_HUB_DISABLE_TELEMETRY", "0") == "0"
def main():
"""Run pytest from the tests directory to avoid import issues."""
# Get the script directory

View File

@@ -4,6 +4,9 @@ import sys
import json
from py.middleware.cache_middleware import cache_control
# Set environment variable to indicate standalone mode
os.environ["COMFYUI_LORA_MANAGER_STANDALONE"] = "1"
# Create mock modules for py/nodes directory - add this before any other imports
def mock_nodes_directory():
"""Create mock modules for all Python files in the py/nodes directory"""