From 0ad92d00b3ee4769fa510ddcda4a6b468837f760 Mon Sep 17 00:00:00 2001 From: pixelpaws Date: Wed, 8 Oct 2025 09:54:36 +0800 Subject: [PATCH] fix(settings): restore legacy settings aliases --- py/lora_manager.py | 4 +++- py/routes/stats_routes.py | 4 +++- py/services/settings_manager.py | 13 +++++++++++-- py/utils/example_images_metadata.py | 10 +++++----- py/utils/example_images_migration.py | 4 +++- py/utils/settings_paths.py | 6 ++++++ 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/py/lora_manager.py b/py/lora_manager.py index 3812b96b..a38325d2 100644 --- a/py/lora_manager.py +++ b/py/lora_manager.py @@ -23,6 +23,8 @@ logger = logging.getLogger(__name__) # Check if we're in standalone mode STANDALONE_MODE = 'nodes' not in sys.modules +settings = get_settings_manager() + class LoraManager: """Main entry point for LoRA Manager plugin""" @@ -51,7 +53,7 @@ class LoraManager: asyncio_logger.addFilter(ConnectionResetFilter()) # Add static route for example images if the path exists in settings - example_images_path = get_settings_manager().get('example_images_path') + example_images_path = settings.get('example_images_path') logger.info(f"Example images path: {example_images_path}") if example_images_path and os.path.exists(example_images_path): app.router.add_static('/example_images_static', example_images_path) diff --git a/py/routes/stats_routes.py b/py/routes/stats_routes.py index b6002e51..b5f69ce0 100644 --- a/py/routes/stats_routes.py +++ b/py/routes/stats_routes.py @@ -15,6 +15,8 @@ from ..utils.usage_stats import UsageStats logger = logging.getLogger(__name__) +settings = get_settings_manager() + class StatsRoutes: """Route handlers for Statistics page and API endpoints""" @@ -66,7 +68,7 @@ class StatsRoutes: is_initializing = lora_initializing or checkpoint_initializing or embedding_initializing # 获取用户语言设置 - settings_manager = get_settings_manager() + settings_manager = settings user_language = settings_manager.get('language', 'en') # 设置服务端i18n语言 diff --git a/py/services/settings_manager.py b/py/services/settings_manager.py index 133e0cc1..7e9311bd 100644 --- a/py/services/settings_manager.py +++ b/py/services/settings_manager.py @@ -692,16 +692,24 @@ class SettingsManager: _SETTINGS_MANAGER: Optional["SettingsManager"] = None _SETTINGS_MANAGER_LOCK = Lock() +# Legacy module-level alias for backwards compatibility with callers that +# monkeypatch ``py.services.settings_manager.settings`` during tests. +settings: Optional["SettingsManager"] = None def get_settings_manager() -> "SettingsManager": """Return the lazily initialised global :class:`SettingsManager`.""" - global _SETTINGS_MANAGER + global _SETTINGS_MANAGER, settings + if settings is not None: + return settings + if _SETTINGS_MANAGER is None: with _SETTINGS_MANAGER_LOCK: if _SETTINGS_MANAGER is None: _SETTINGS_MANAGER = SettingsManager() + + settings = _SETTINGS_MANAGER return _SETTINGS_MANAGER @@ -712,6 +720,7 @@ def reset_settings_manager() -> None: directory before the manager touches the filesystem. """ - global _SETTINGS_MANAGER + global _SETTINGS_MANAGER, settings with _SETTINGS_MANAGER_LOCK: _SETTINGS_MANAGER = None + settings = None diff --git a/py/utils/example_images_metadata.py b/py/utils/example_images_metadata.py index f6ef6b52..459f3ff0 100644 --- a/py/utils/example_images_metadata.py +++ b/py/utils/example_images_metadata.py @@ -20,22 +20,22 @@ _preview_service = PreviewAssetService( exif_utils=ExifUtils, ) -_METADATA_SYNC_SERVICE: MetadataSyncService | None = None +_metadata_sync_service: MetadataSyncService | None = None def _get_metadata_sync_service() -> MetadataSyncService: """Return the shared metadata sync service, initialising it lazily.""" - global _METADATA_SYNC_SERVICE - if _METADATA_SYNC_SERVICE is None: - _METADATA_SYNC_SERVICE = MetadataSyncService( + global _metadata_sync_service + if _metadata_sync_service is None: + _metadata_sync_service = MetadataSyncService( metadata_manager=MetadataManager, preview_service=_preview_service, settings=get_settings_manager(), default_metadata_provider_factory=get_default_metadata_provider, metadata_provider_selector=get_metadata_provider, ) - return _METADATA_SYNC_SERVICE + return _metadata_sync_service class MetadataUpdater: diff --git a/py/utils/example_images_migration.py b/py/utils/example_images_migration.py index 695b4d42..390f5e33 100644 --- a/py/utils/example_images_migration.py +++ b/py/utils/example_images_migration.py @@ -14,13 +14,15 @@ logger = logging.getLogger(__name__) CURRENT_NAMING_VERSION = 2 # Increment this when naming conventions change +settings = get_settings_manager() + class ExampleImagesMigration: """Handles migrations for example images naming conventions""" @staticmethod async def check_and_run_migrations(): """Check if migrations are needed and run them in background""" - root = get_settings_manager().get('example_images_path') + root = settings.get('example_images_path') if not root or not os.path.exists(root): logger.debug("No example images path configured or path doesn't exist, skipping migrations") return diff --git a/py/utils/settings_paths.py b/py/utils/settings_paths.py index 0a05b3da..290fd353 100644 --- a/py/utils/settings_paths.py +++ b/py/utils/settings_paths.py @@ -65,6 +65,12 @@ def ensure_settings_file(logger: Optional[logging.Logger] = None) -> str: logger = logger or _LOGGER target_path = get_settings_file_path(create_dir=True) + preferred_dir = user_config_dir(APP_NAME, appauthor=False) + preferred_path = os.path.join(preferred_dir, "settings.json") + + if os.path.abspath(target_path) != os.path.abspath(preferred_path): + os.makedirs(preferred_dir, exist_ok=True) + target_path = preferred_path legacy_path = get_legacy_settings_path() if os.path.exists(legacy_path) and not os.path.exists(target_path):