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.
This commit is contained in:
psychedelicious 2024-03-19 15:53:04 +11:00
parent 6af6673a4f
commit ee3096f616
2 changed files with 7 additions and 0 deletions

View File

@ -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))

View File

@ -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