mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-08-22 21:41:27 -03:00
Compare commits
2 Commits
4f016a8024
...
6470021e77
| Author | SHA1 | Date | |
|---|---|---|---|
| 6470021e77 | |||
| 71658ab37b |
@@ -152,6 +152,11 @@ class SettingsManager:
|
|||||||
self._check_environment_variables()
|
self._check_environment_variables()
|
||||||
self._collect_configuration_warnings()
|
self._collect_configuration_warnings()
|
||||||
|
|
||||||
|
if os.environ.get("LORA_MANAGER_PORTABLE", "0") == "1":
|
||||||
|
if not self.settings.get("use_portable_settings"):
|
||||||
|
self.settings["use_portable_settings"] = True
|
||||||
|
self._save_settings()
|
||||||
|
|
||||||
if self._needs_initial_save:
|
if self._needs_initial_save:
|
||||||
self._save_settings()
|
self._save_settings()
|
||||||
self._needs_initial_save = False
|
self._needs_initial_save = False
|
||||||
@@ -1797,6 +1802,9 @@ class SettingsManager:
|
|||||||
if key in self.settings:
|
if key in self.settings:
|
||||||
minimal[key] = copy.deepcopy(self.settings[key])
|
minimal[key] = copy.deepcopy(self.settings[key])
|
||||||
|
|
||||||
|
if self.settings.get("use_portable_settings"):
|
||||||
|
minimal["use_portable_settings"] = True
|
||||||
|
|
||||||
if self._seed_template:
|
if self._seed_template:
|
||||||
for key, value in self._seed_template.items():
|
for key, value in self._seed_template.items():
|
||||||
minimal.setdefault(key, copy.deepcopy(value))
|
minimal.setdefault(key, copy.deepcopy(value))
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from platformdirs import user_config_dir
|
|||||||
|
|
||||||
|
|
||||||
APP_NAME = "ComfyUI-LoRA-Manager"
|
APP_NAME = "ComfyUI-LoRA-Manager"
|
||||||
|
_LM_PORTABLE_ENV = "LORA_MANAGER_PORTABLE"
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -100,7 +101,11 @@ def ensure_settings_file(logger: Optional[logging.Logger] = None) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _should_use_portable_settings(path: str, logger: logging.Logger) -> bool:
|
def _should_use_portable_settings(path: str, logger: logging.Logger) -> bool:
|
||||||
"""Return ``True`` when the repository settings file enables portable mode."""
|
"""Return ``True`` when the env var forces it or the settings file enables it."""
|
||||||
|
|
||||||
|
if os.environ.get(_LM_PORTABLE_ENV, "0") == "1":
|
||||||
|
logger.debug("Portable mode enabled via %s", _LM_PORTABLE_ENV)
|
||||||
|
return True
|
||||||
|
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
"""Tests for settings path resolution."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from py.utils.settings_paths import _should_use_portable_settings
|
||||||
|
|
||||||
|
|
||||||
|
class TestShouldUsePortableSettings:
|
||||||
|
"""Tests for _should_use_portable_settings()."""
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"env_value, settings_flag, expected",
|
||||||
|
[
|
||||||
|
("1", False, True), # env = 1 overrides settings.json false
|
||||||
|
("1", True, True), # env = 1 matches settings.json true
|
||||||
|
("0", False, False), # env = 0 → rely on settings.json
|
||||||
|
("0", True, True), # env = 0 → rely on settings.json
|
||||||
|
("", False, False), # unset → rely on settings.json
|
||||||
|
("", True, True), # unset → rely on settings.json
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_env_var_overrides_settings(self, tmp_path, env_value, settings_flag, expected):
|
||||||
|
"""The LORA_MANAGER_PORTABLE env var takes precedence over settings.json."""
|
||||||
|
settings_file = tmp_path / "settings.json"
|
||||||
|
settings_file.write_text(
|
||||||
|
json.dumps({"use_portable_settings": settings_flag})
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.MonkeyPatch.context() as mp:
|
||||||
|
if env_value:
|
||||||
|
mp.setenv("LORA_MANAGER_PORTABLE", env_value)
|
||||||
|
else:
|
||||||
|
mp.delenv("LORA_MANAGER_PORTABLE", raising=False)
|
||||||
|
|
||||||
|
result = _should_use_portable_settings(str(settings_file), logging.getLogger())
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
|
def test_missing_file_without_env(self, tmp_path):
|
||||||
|
"""Without env var, missing settings file returns False."""
|
||||||
|
missing = tmp_path / "nonexistent.json"
|
||||||
|
|
||||||
|
result = _should_use_portable_settings(str(missing), logging.getLogger())
|
||||||
|
assert result is False
|
||||||
|
|
||||||
|
def test_missing_file_with_env(self, tmp_path):
|
||||||
|
"""With env var, even a missing settings file returns True."""
|
||||||
|
missing = tmp_path / "nonexistent.json"
|
||||||
|
|
||||||
|
with pytest.MonkeyPatch.context() as mp:
|
||||||
|
mp.setenv("LORA_MANAGER_PORTABLE", "1")
|
||||||
|
result = _should_use_portable_settings(str(missing), logging.getLogger())
|
||||||
|
assert result is True
|
||||||
Reference in New Issue
Block a user