Skip to content

Commit

Permalink
Merge branch 'ci/support-multiple-inheritance' of github.com:bakdata/…
Browse files Browse the repository at this point in the history
…kpops into ci/support-multiple-inheritance
  • Loading branch information
sujuka99 committed Jan 11, 2024
2 parents 6e6f625 + d54e7d1 commit 26e6893
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,51 +89,43 @@ kpops_components_inheritance_ref:
bases:
- kubernetes-app
parents:
- helm-app
- kubernetes-app
- pipeline-component
kafka-app:
bases:
- pipeline-component
parents:
- kafka-app
- pipeline-component
kafka-connector:
bases:
- pipeline-component
parents:
- kafka-connector
- pipeline-component
kafka-sink-connector:
bases:
- kafka-connector
parents:
- kafka-sink-connector
- kafka-connector
- pipeline-component
kafka-source-connector:
bases:
- kafka-connector
parents:
- kafka-source-connector
- kafka-connector
- pipeline-component
kubernetes-app:
bases:
- pipeline-component
parents:
- kubernetes-app
- pipeline-component
pipeline-component:
bases: []
parents:
- pipeline-component
parents: []
producer-app:
bases:
- kafka-app
- streams-bootstrap
parents:
- producer-app
- kafka-app
- streams-bootstrap
- helm-app
Expand All @@ -144,7 +136,6 @@ kpops_components_inheritance_ref:
- kafka-app
- streams-bootstrap
parents:
- streams-app
- kafka-app
- streams-bootstrap
- helm-app
Expand All @@ -154,7 +145,6 @@ kpops_components_inheritance_ref:
bases:
- helm-app
parents:
- streams-bootstrap
- helm-app
- kubernetes-app
- pipeline-component
2 changes: 1 addition & 1 deletion hooks/gen_docs/gen_docs_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
type[PipelineComponent],
parent,
).type
for parent in component.get_parents(PipelineComponent)
for parent in component.parents
],
}
for component in KPOPS_COMPONENTS
Expand Down
31 changes: 16 additions & 15 deletions kpops/components/base_components/pipeline_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
TopicConfig,
ToSection,
)
from kpops.utils import cached_classproperty
from kpops.utils.docstring import describe_attr
from kpops.utils.pydantic import issubclass_patched

Expand Down Expand Up @@ -70,21 +71,21 @@ def __init__(self, **kwargs) -> None:
def full_name(self) -> str:
return self.prefix + self.name

@classmethod
def get_parents(
cls: type[Self], __class_or_tuple: type = BaseDefaultsComponent
) -> list[str]:
"""Get kebab-cased superclasses' names.
:param __class_or_tuple: "Furthest" ancestors to look for,
defaults to BaseDefaultsComponent
:return: All ancestors that match the requirements
"""
bases = []
for base in cls.mro():
if issubclass_patched(base, __class_or_tuple):
bases.append(base)
return bases
@cached_classproperty
def parents(cls: type[Self]) -> tuple[type[PipelineComponent], ...]: # pyright: ignore[reportGeneralTypeIssues]
"""Get parent components.
:return: All ancestor KPOps components
"""

def gen_parents():
for base in cls.mro():
# skip class itself and non-component ancestors
if base is cls or not issubclass_patched(base, PipelineComponent):
continue
yield base

return tuple(gen_parents())

def add_input_topics(self, topics: list[str]) -> None:
"""Add given topics to the list of input topics.
Expand Down
4 changes: 3 additions & 1 deletion kpops/utils/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def exclude_defaults(model: BaseModel, dumped_model: dict[str, _V]) -> dict[str,
}


def issubclass_patched(__cls: type, __class_or_tuple: type = BaseModel) -> bool:
def issubclass_patched(
__cls: type, __class_or_tuple: type | tuple[type, ...] = BaseModel
) -> bool:
"""Pydantic breaks ``issubclass``.
``issubclass(set[str], set) # True``
Expand Down

0 comments on commit 26e6893

Please sign in to comment.