From b8c46fb15b8517f561fba9ce78d3f635fecdd7d5 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:16:21 +1100 Subject: [PATCH] fix(config): split check_invokeai_root into separate function to validate, use this in model_install to determine if need to run configurator --- invokeai/backend/install/check_root.py | 8 ++++++-- invokeai/frontend/install/model_install.py | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/invokeai/backend/install/check_root.py b/invokeai/backend/install/check_root.py index d2b7f592e4..a24bc76295 100644 --- a/invokeai/backend/install/check_root.py +++ b/invokeai/backend/install/check_root.py @@ -7,10 +7,14 @@ import sys from invokeai.app.services.config import InvokeAIAppConfig +def validate_root_structure(config: InvokeAIAppConfig) -> None: + assert config.db_path.parent.exists(), f"{config.db_path.parent} not found" + assert config.models_path.exists(), f"{config.models_path} not found" + + def check_invokeai_root(config: InvokeAIAppConfig): try: - assert config.db_path.parent.exists(), f"{config.db_path.parent} not found" - assert config.models_path.exists(), f"{config.models_path} not found" + validate_root_structure(config) except Exception as e: print() print(f"An exception has occurred: {str(e)}") diff --git a/invokeai/frontend/install/model_install.py b/invokeai/frontend/install/model_install.py index 6d5cd6f32a..9e43ff9c06 100644 --- a/invokeai/frontend/install/model_install.py +++ b/invokeai/frontend/install/model_install.py @@ -22,8 +22,9 @@ import npyscreen import torch from npyscreen import widget -from invokeai.app.services.config import InvokeAIAppConfig +from invokeai.app.services.config.config_default import get_config from invokeai.app.services.model_install import ModelInstallServiceBase +from invokeai.backend.install.check_root import validate_root_structure from invokeai.backend.install.install_helper import InstallHelper, InstallSelections, UnifiedModelInfo from invokeai.backend.model_manager import ModelType from invokeai.backend.util import choose_precision, choose_torch_device @@ -41,8 +42,8 @@ from invokeai.frontend.install.widgets import ( ) warnings.filterwarnings("ignore", category=UserWarning) # noqa: E402 -config = InvokeAIAppConfig.get_config() -logger = InvokeAILogger.get_logger("ModelInstallService") +config = get_config() +logger = InvokeAILogger.get_logger("ModelInstallService", config=config) # logger.setLevel("WARNING") # logger.setLevel('DEBUG') @@ -600,15 +601,17 @@ def main() -> None: ) opt = parser.parse_args() - invoke_args = [] + invoke_args: dict[str, Any] = {} if opt.root: - invoke_args.extend(["--root", opt.root]) + invoke_args["root"] = opt.root if opt.full_precision: - invoke_args.extend(["--precision", "float32"]) - config.parse_args(invoke_args) + invoke_args["precision"] = "float32" + config.update_config(invoke_args) logger = InvokeAILogger().get_logger(config=config) - if not config.models_path.exists(): + try: + validate_root_structure(config) + except AssertionError: logger.info("Your InvokeAI root directory is not set up. Calling invokeai-configure.") sys.argv = ["invokeai_configure", "--yes", "--skip-sd-weights"] from invokeai.frontend.install.invokeai_configure import invokeai_configure