diff --git a/invokeai/app/services/config.py b/invokeai/app/services/config.py index c75c0602b1..434ba47fc1 100644 --- a/invokeai/app/services/config.py +++ b/invokeai/app/services/config.py @@ -356,7 +356,6 @@ def _find_root() -> Path: venv = Path(os.environ.get("VIRTUAL_ENV") or ".") if os.environ.get("INVOKEAI_ROOT"): root = Path(os.environ.get("INVOKEAI_ROOT")).resolve() - os.environ["INVOKEAI_ROOT"] = str(root) # absolutize it to protect against code doing a cwd() elif any([(venv.parent / x).exists() for x in [INIT_FILE, LEGACY_INIT_FILE]]): root = (venv.parent).resolve() else: @@ -403,7 +402,7 @@ class InvokeAIAppConfig(InvokeAISettings): xformers_enabled : bool = Field(default=True, description="Enable/disable memory-efficient attention", category='Memory/Performance') tiled_decode : bool = Field(default=False, description="Whether to enable tiled VAE decode (reduces memory consumption with some performance penalty)", category='Memory/Performance') - root : Path = Field(default=_find_root(), description='InvokeAI runtime root directory', category='Paths') + root : Path = Field(default=None, description='InvokeAI runtime root directory', category='Paths') autoimport_dir : Path = Field(default='autoimport', description='Path to a directory of models files to be imported on startup.', category='Paths') lora_dir : Path = Field(default=None, description='Path to a directory of LoRA/LyCORIS models to be imported on startup.', category='Paths') embedding_dir : Path = Field(default=None, description='Path to a directory of Textual Inversion embeddings to be imported on startup.', category='Paths') @@ -475,6 +474,7 @@ class InvokeAIAppConfig(InvokeAISettings): root = Path(self.root).expanduser().absolute() else: root = self.find_root() + self.root = root # insulate ourselves from relative paths that may change return root @property diff --git a/tests/test_config.py b/tests/test_config.py index 5d3dc46aa4..a84af80eb9 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -84,6 +84,20 @@ def test_env_override(): assert conf.max_cache_size == 20 +def test_root_resists_cwd(): + previous = os.environ["INVOKEAI_ROOT"] + cwd = Path(os.getcwd()).resolve() + + os.environ["INVOKEAI_ROOT"] = "." + conf = InvokeAIAppConfig.get_config() + conf.parse_args([]) + assert conf.root_path == cwd + + os.chdir(previous) + assert conf.root_path == cwd + os.environ["INVOKEAI_ROOT"] = previous + + def test_type_coercion(): conf = InvokeAIAppConfig().get_config() conf.parse_args(argv=["--root=/tmp/foobar"])