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 import folder_paths # type: ignore
from typing import List from typing import List
import logging import logging
import sys
import json import json
import urllib.parse import urllib.parse
# Check if running in standalone mode # Use an environment variable to control standalone mode
standalone_mode = 'nodes' not in sys.modules standalone_mode = os.environ.get("HF_HUB_DISABLE_TELEMETRY", "0") == "0"
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@@ -1,9 +1,7 @@
import os import os
import importlib
import sys
# Check if running in standalone mode # 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: if not standalone_mode:
from .metadata_hook import MetadataHook from .metadata_hook import MetadataHook

View File

@@ -1,9 +1,9 @@
import json import json
import sys import os
from .constants import IMAGES from .constants import IMAGES
# Check if running in standalone mode # 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 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 from ..services.downloader import get_downloader
logger = logging.getLogger(__name__) 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 # Node registry for tracking active workflow nodes
class NodeRegistry: class NodeRegistry:

View File

@@ -21,7 +21,7 @@ from ..services.server_i18n import server_i18n
from ..config import config from ..config import config
# Check if running in standalone mode # 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.service_registry import ServiceRegistry # Add ServiceRegistry import
from ..services.downloader import get_downloader from ..services.downloader import get_downloader

View File

@@ -1,6 +1,5 @@
import os import os
import json import json
import sys
import time import time
import asyncio import asyncio
import logging import logging
@@ -12,7 +11,7 @@ from ..config import config
from ..services.service_registry import ServiceRegistry from ..services.service_registry import ServiceRegistry
# Check if running in standalone mode # 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: if not standalone_mode:
from ..metadata_collector.metadata_registry import MetadataRegistry from ..metadata_collector.metadata_registry import MetadataRegistry

View File

@@ -10,6 +10,10 @@ import sys
import os import os
from pathlib import Path 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(): def main():
"""Run pytest from the tests directory to avoid import issues.""" """Run pytest from the tests directory to avoid import issues."""
# Get the script directory # Get the script directory

View File

@@ -4,6 +4,9 @@ import sys
import json import json
from py.middleware.cache_middleware import cache_control 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 # Create mock modules for py/nodes directory - add this before any other imports
def mock_nodes_directory(): def mock_nodes_directory():
"""Create mock modules for all Python files in the py/nodes directory""" """Create mock modules for all Python files in the py/nodes directory"""