diff --git a/hooks/gen_docs/gen_docs_env_vars.py b/hooks/gen_docs/gen_docs_env_vars.py index f0cd71a74..0f1b7a829 100644 --- a/hooks/gen_docs/gen_docs_env_vars.py +++ b/hooks/gen_docs/gen_docs_env_vars.py @@ -10,7 +10,6 @@ from textwrap import fill from typing import Any -from pydantic import BaseModel from pydantic_core import PydanticUndefined from pytablewriter import MarkdownTableWriter from typer.models import ArgumentInfo, OptionInfo @@ -20,7 +19,7 @@ from kpops.cli import main from kpops.config import KpopsConfig from kpops.utils.dict_ops import generate_substitution -from kpops.utils.pydantic import issubclass_patched +from kpops.utils.pydantic import collect_fields PATH_DOCS_RESOURCES = ROOT / "docs/docs/resources" PATH_DOCS_VARIABLES = PATH_DOCS_RESOURCES / "variables" @@ -275,21 +274,6 @@ def fill_csv_pipeline_config(target: Path) -> None: ) -def collect_fields(model: type[BaseModel]) -> dict[str, Any]: - """Collect and return a ``dict`` of all fields in a settings class. - - :param model: settings class - :return: ``dict`` of all fields in a settings class - """ - seen_fields = {} - for field_name, field_value in model.model_fields.items(): - if field_value.annotation and issubclass_patched(field_value.annotation): - seen_fields[field_name] = collect_fields(field_value.annotation) - else: - seen_fields[field_name] = field_value - return seen_fields - - def fill_csv_cli(target: Path) -> None: """Append all CLI-commands-related env vars to a ``.csv`` file. diff --git a/kpops/utils/cli_commands.py b/kpops/utils/cli_commands.py index 27cfc6b6d..c2c994341 100644 --- a/kpops/utils/cli_commands.py +++ b/kpops/utils/cli_commands.py @@ -6,11 +6,10 @@ from pydantic.fields import FieldInfo from pydantic_core import PydanticUndefined -from hooks.gen_docs.gen_docs_env_vars import collect_fields from kpops.config import KpopsConfig from kpops.utils.docstring import describe_object from kpops.utils.json import is_jsonable -from kpops.utils.pydantic import issubclass_patched +from kpops.utils.pydantic import collect_fields, issubclass_patched def extract_config_fields_for_yaml( diff --git a/kpops/utils/pydantic.py b/kpops/utils/pydantic.py index 1cb972492..9465259ee 100644 --- a/kpops/utils/pydantic.py +++ b/kpops/utils/pydantic.py @@ -99,6 +99,21 @@ def exclude_defaults(model: BaseModel, dumped_model: dict[str, _V]) -> dict[str, } +def collect_fields(model: type[BaseModel]) -> dict[str, Any]: + """Collect and return a ``dict`` of all fields in a settings class. + + :param model: settings class + :return: ``dict`` of all fields in a settings class + """ + seen_fields = {} + for field_name, field_value in model.model_fields.items(): + if field_value.annotation and issubclass_patched(field_value.annotation): + seen_fields[field_name] = collect_fields(field_value.annotation) + else: + seen_fields[field_name] = field_value + return seen_fields + + def issubclass_patched( __cls: type, __class_or_tuple: type | tuple[type, ...] = BaseModel ) -> bool: