|
|
import os |
|
|
from typing import Literal, get_args, get_type_hints |
|
|
|
|
|
from invokeai.app.services.config.config_default import InvokeAIAppConfig |
|
|
|
|
|
_excluded = {"schema_version", "legacy_models_yaml_path"} |
|
|
|
|
|
|
|
|
def generate_config_docstrings() -> str: |
|
|
"""Helper function for mkdocs. Generates a docstring for the InvokeAIAppConfig class. |
|
|
|
|
|
You shouldn't run this manually. Instead, run `scripts/update-config-docstring.py` to update the docstring. |
|
|
A makefile target is also available: `make update-config-docstring`. |
|
|
|
|
|
See that script for more information about why this is necessary. |
|
|
""" |
|
|
docstring = ' """Invoke\'s global app configuration.\n\n' |
|
|
docstring += " Typically, you won't need to interact with this class directly. Instead, use the `get_config` function from `invokeai.app.services.config` to get a singleton config object.\n\n" |
|
|
docstring += " Attributes:\n" |
|
|
|
|
|
field_descriptions: list[str] = [] |
|
|
type_hints = get_type_hints(InvokeAIAppConfig) |
|
|
|
|
|
for k, v in InvokeAIAppConfig.model_fields.items(): |
|
|
if v.exclude or k in _excluded: |
|
|
continue |
|
|
field_type = type_hints.get(k) |
|
|
extra = "" |
|
|
if getattr(field_type, "__origin__", None) is Literal: |
|
|
|
|
|
options = [f"`{str(x)}`" for x in get_args(field_type)] |
|
|
extra = f"<br>Valid values: {', '.join(options)}" |
|
|
field_descriptions.append(f" {k}: {v.description}{extra}") |
|
|
|
|
|
docstring += "\n".join(field_descriptions) |
|
|
docstring += '\n """' |
|
|
|
|
|
return docstring |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
|
|
os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) |
|
|
|
|
|
docstring = generate_config_docstrings() |
|
|
|
|
|
|
|
|
with open("invokeai/app/services/config/config_default.py", "r") as f: |
|
|
lines = f.readlines() |
|
|
|
|
|
|
|
|
class_def_index = next(i for i, line in enumerate(lines) if "class InvokeAIAppConfig" in line) |
|
|
|
|
|
|
|
|
docstring_start_index = next(i for i, line in enumerate(lines[class_def_index:]) if '"""' in line) + class_def_index |
|
|
docstring_end_index = ( |
|
|
next(i for i, line in enumerate(lines[docstring_start_index + 1 :]) if '"""' in line) |
|
|
+ docstring_start_index |
|
|
+ 1 |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
lines = lines[:docstring_start_index] + [docstring, "\n"] + lines[docstring_end_index + 1 :] |
|
|
|
|
|
|
|
|
with open("invokeai/app/services/config/config_default.py", "w") as f: |
|
|
f.writelines(lines) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|