From ee3096f61650f03a083f88fb3e3473a7bca9dc28 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:53:04 +1100 Subject: [PATCH] feat(config): add flag to indicate if args were parsed This flag acts as a proxy for the `get_config()` function to determine if the full application is running. If it was, the config will set the root, do HF login, etc. If not (e.g. it's called by an external script), all that stuff will be skipped. --- invokeai/app/services/config/config_default.py | 5 +++++ invokeai/frontend/cli/arg_parser.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/invokeai/app/services/config/config_default.py b/invokeai/app/services/config/config_default.py index 3730b3508d..10d8ba308f 100644 --- a/invokeai/app/services/config/config_default.py +++ b/invokeai/app/services/config/config_default.py @@ -436,6 +436,11 @@ def get_config() -> InvokeAIAppConfig: args = InvokeAIArgs.args + # This flag serves as a proxy for whether the config was retrieved in the context of the full application or not. + # If it is False, we should just return a default config and not set the root, log in to HF, etc. + if not InvokeAIArgs.did_parse: + return config + # CLI args trump environment variables if root := getattr(args, "root", None): config.set_root(Path(root)) diff --git a/invokeai/frontend/cli/arg_parser.py b/invokeai/frontend/cli/arg_parser.py index 7db06fddd9..34f7c462bb 100644 --- a/invokeai/frontend/cli/arg_parser.py +++ b/invokeai/frontend/cli/arg_parser.py @@ -34,9 +34,11 @@ class InvokeAIArgs: """ args: Optional[Namespace] = None + did_parse: bool = False @staticmethod def parse_args() -> Optional[Namespace]: """Parse CLI args and store the result.""" InvokeAIArgs.args = _parser.parse_args() + InvokeAIArgs.did_parse = True return InvokeAIArgs.args