mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(config): ignore empty environment variables (use default values instead)
This commit is contained in:
parent
beffca6b49
commit
e32c609fec
@ -174,14 +174,15 @@ class InvokeAIAppConfig(BaseSettings):
|
|||||||
|
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
model_config = SettingsConfigDict(env_file_encoding="utf-8", case_sensitive=True, env_prefix="INVOKEAI")
|
model_config = SettingsConfigDict(env_prefix="INVOKEAI_", env_ignore_empty=True)
|
||||||
|
|
||||||
def update_config(self, config: dict[str, Any] | InvokeAIAppConfig) -> None:
|
def update_config(self, config: dict[str, Any] | InvokeAIAppConfig, clobber: bool = True) -> None:
|
||||||
"""Updates the config, overwriting existing values.
|
"""Updates the config, overwriting existing values.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
config: A dictionary of config settings, or instance of `InvokeAIAppConfig`. If an instance of \
|
config: A dictionary of config settings, or instance of `InvokeAIAppConfig`. If an instance of \
|
||||||
`InvokeAIAppConfig`, only the explicitly set fields will be merged into the singleton config.
|
`InvokeAIAppConfig`, only the explicitly set fields will be merged into the singleton config.
|
||||||
|
clobber: If `True`, overwrite existing values. If `False`, only update fields that are not already set.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if isinstance(config, dict):
|
if isinstance(config, dict):
|
||||||
@ -192,6 +193,10 @@ class InvokeAIAppConfig(BaseSettings):
|
|||||||
for field_name in new_config.model_fields_set:
|
for field_name in new_config.model_fields_set:
|
||||||
new_value = getattr(new_config, field_name)
|
new_value = getattr(new_config, field_name)
|
||||||
current_value = getattr(self, field_name)
|
current_value = getattr(self, field_name)
|
||||||
|
|
||||||
|
if field_name in self.model_fields_set and not clobber:
|
||||||
|
continue
|
||||||
|
|
||||||
if new_value != current_value:
|
if new_value != current_value:
|
||||||
setattr(self, field_name, new_value)
|
setattr(self, field_name, new_value)
|
||||||
|
|
||||||
@ -223,7 +228,8 @@ class InvokeAIAppConfig(BaseSettings):
|
|||||||
"""
|
"""
|
||||||
path = source_path or self.init_file_path
|
path = source_path or self.init_file_path
|
||||||
config_from_file = load_and_migrate_config(path)
|
config_from_file = load_and_migrate_config(path)
|
||||||
self.update_config(config_from_file)
|
# Clobbering here will overwrite any settings that were set via environment variables
|
||||||
|
self.update_config(config_from_file, clobber=False)
|
||||||
|
|
||||||
def set_root(self, root: Path) -> None:
|
def set_root(self, root: Path) -> None:
|
||||||
"""Set the runtime root directory. This is typically set using a CLI arg."""
|
"""Set the runtime root directory. This is typically set using a CLI arg."""
|
||||||
@ -415,6 +421,7 @@ def get_config() -> InvokeAIAppConfig:
|
|||||||
|
|
||||||
args = InvokeAIArgs.args
|
args = InvokeAIArgs.args
|
||||||
|
|
||||||
|
# CLI args trump environment variables
|
||||||
if root := getattr(args, "root", None):
|
if root := getattr(args, "root", None):
|
||||||
config.set_root(Path(root))
|
config.set_root(Path(root))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user