Skip to content

Commit

Permalink
Add components property to registry
Browse files Browse the repository at this point in the history
  • Loading branch information
disrupted committed Jun 27, 2024
1 parent e454b1a commit 6809be3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
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 @@ -39,7 +39,7 @@
(PATH_DOCS_RESOURCES / "pipeline-defaults/headers").iterdir(),
)

KPOPS_COMPONENTS = tuple(registry._classes.values())
KPOPS_COMPONENTS = tuple(registry.components)
KPOPS_COMPONENTS_SECTIONS = {
component.type: [
field_name
Expand Down
4 changes: 4 additions & 0 deletions kpops/api/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class Registry:

_classes: ClassDict[PipelineComponent] = field(default_factory=dict, init=False)

@property
def components(self) -> Iterator[type[PipelineComponent]]:
yield from self._classes.values()

def discover_components(self) -> None:
"""Discover first- and third-party KPOps components.
Expand Down
2 changes: 1 addition & 1 deletion kpops/utils/gen_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MultiComponentGenerateJsonSchema(GenerateJsonSchema): ...

registry = Registry()
registry.discover_components()
COMPONENTS = tuple(registry._classes.values())
COMPONENTS = tuple(registry.components)


def print_schema(model: type[BaseModel]) -> None:
Expand Down
10 changes: 2 additions & 8 deletions tests/cli/test_schema_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from pydantic import ConfigDict, Field
from typer.testing import CliRunner

from kpops.api.registry import Registry
from kpops.cli.main import app
from kpops.components.base_components.pipeline_component import PipelineComponent
from kpops.utils.docstring import describe_attr
from kpops.utils.gen_schema import COMPONENTS

RESOURCE_PATH = Path(__file__).parent / "resources"

Expand Down Expand Up @@ -76,12 +76,6 @@ class SubPipelineComponentCorrectDocstr(SubPipelineComponent):
"ignore:handlers", "ignore:config", "ignore:enrich", "ignore:validate"
)
class TestGenSchema:
@pytest.fixture
def stock_components(self) -> list[type[PipelineComponent]]:
registry = Registry()
registry.discover_components()
return list(registry._classes.values())

def test_gen_pipeline_schema_stock_and_custom_module(self):
result = runner.invoke(
app,
Expand Down Expand Up @@ -109,7 +103,7 @@ def test_gen_defaults_schema(self, stock_components: list[type[PipelineComponent
assert result.stdout
schema = json.loads(result.stdout)
assert schema["title"] == "DefaultsSchema"
assert schema["required"] == [component.type for component in stock_components]
assert schema["required"] == [component.type for component in COMPONENTS]

def test_gen_config_schema(self):
result = runner.invoke(
Expand Down

0 comments on commit 6809be3

Please sign in to comment.