Skip to content

Commit

Permalink
Fix import errors (#472)
Browse files Browse the repository at this point in the history
`ModuleNotFoundError: No module named 'hooks'`
  • Loading branch information
sujuka99 authored Mar 11, 2024
1 parent 760d755 commit c2ca0c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
18 changes: 1 addition & 17 deletions hooks/gen_docs/gen_docs_env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions kpops/utils/cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions kpops/utils/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c2ca0c6

Please sign in to comment.