mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-09-20 18:51:26 -03:00
feat(settings): add an explicit opt-out from persisted portable mode
Setting LORA_MANAGER_PORTABLE=1 once wrote use_portable_settings: true into the plugin's own settings.json, and every later run of every instance sharing that plugin folder then read and wrote the portable settings directory. There was no way back except editing the file by hand, which is exactly the trap a user hit while following the FAQ's instructions for isolating a second instance (#1114). LORA_MANAGER_PORTABLE=0 is now the explicit exit: - _should_use_portable_settings honours "0" as a forced off, so the resolved settings directory no longer depends on the persisted flag. - SettingsManager clears the persisted flag in that case, so later runs without the variable stay on the shared settings directory. Unset or unrecognised values keep the previous behaviour: the persisted flag decides, so existing portable installs are unaffected. LORA_MANAGER_SETTINGS_DIR still takes precedence over both.
This commit is contained in:
@@ -174,12 +174,42 @@ def ensure_settings_file(logger: Optional[logging.Logger] = None) -> str:
|
||||
return target_path
|
||||
|
||||
|
||||
def _portable_env_override() -> Optional[bool]:
|
||||
"""Return the portable mode forced by ``LORA_MANAGER_PORTABLE``, if any.
|
||||
|
||||
Returns:
|
||||
``True`` when the variable enables portable mode, ``False`` when it is
|
||||
explicitly set to ``"0"``, and ``None`` when it is unset or holds some
|
||||
other value (in which case the persisted settings flag decides).
|
||||
"""
|
||||
|
||||
raw = os.environ.get(_LM_PORTABLE_ENV)
|
||||
if raw is None:
|
||||
return None
|
||||
if raw == "1":
|
||||
return True
|
||||
if raw == "0":
|
||||
return False
|
||||
return None
|
||||
|
||||
|
||||
def _should_use_portable_settings(path: str, logger: logging.Logger) -> bool:
|
||||
"""Return ``True`` when the env var forces it or the settings file enables it."""
|
||||
|
||||
if os.environ.get(_LM_PORTABLE_ENV, "0") == "1":
|
||||
override = _portable_env_override()
|
||||
if override is True:
|
||||
logger.debug("Portable mode enabled via %s", _LM_PORTABLE_ENV)
|
||||
return True
|
||||
if override is False:
|
||||
# Explicit opt-out. Without this, a single `LORA_MANAGER_PORTABLE=1`
|
||||
# run would pin the shared plugin settings.json to portable mode
|
||||
# forever, with no way back except editing that file by hand.
|
||||
logger.info(
|
||||
"Portable mode disabled via %s=%s",
|
||||
_LM_PORTABLE_ENV,
|
||||
os.environ.get(_LM_PORTABLE_ENV, ""),
|
||||
)
|
||||
return False
|
||||
|
||||
if not os.path.exists(path):
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user