Skip to content

Commit

Permalink
Update files
Browse files Browse the repository at this point in the history
  • Loading branch information
raminqaf committed May 24, 2024
1 parent 0d286de commit 98f519b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 35 deletions.
16 changes: 8 additions & 8 deletions hooks/gen_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from pathlib import Path

from hooks import ROOT
from kpops.api.file_type import KpopsFileType
from kpops.utils.gen_schema import (
SchemaScope,
gen_config_schema,
gen_defaults_schema,
gen_pipeline_schema,
Expand All @@ -15,7 +15,7 @@
PATH_TO_SCHEMA = ROOT / "docs/docs/schema"


def gen_schema(scope: SchemaScope):
def gen_schema(scope: KpopsFileType):
"""Generate the specified schema and save it to a file.
The file is located in docs/docs/schema and is named ``<scope.value>.json``
Expand All @@ -24,16 +24,16 @@ def gen_schema(scope: SchemaScope):
"""
with redirect_stdout(StringIO()) as f:
match scope:
case SchemaScope.PIPELINE:
case KpopsFileType.PIPELINE:
gen_pipeline_schema()
case SchemaScope.DEFAULTS:
case KpopsFileType.DEFAULTS:
gen_defaults_schema()
case SchemaScope.CONFIG:
case KpopsFileType.CONFIG:
gen_config_schema()
Path(PATH_TO_SCHEMA / f"{scope.value}.json").write_text(f.getvalue())


if __name__ == "__main__":
gen_schema(SchemaScope.PIPELINE)
gen_schema(SchemaScope.DEFAULTS)
gen_schema(SchemaScope.CONFIG)
gen_schema(KpopsFileType.PIPELINE)
gen_schema(KpopsFileType.DEFAULTS)
gen_schema(KpopsFileType.CONFIG)
4 changes: 3 additions & 1 deletion kpops/api/kpops_resources.py → kpops/api/file_type.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

from enum import Enum

FILE_PREFIX = ".yaml"


class KpopsResources(str, Enum):
class KpopsFileType(str, Enum):
PIPELINE = "pipeline"
DEFAULTS = "defaults"
CONFIG = "config"
Expand Down
10 changes: 5 additions & 5 deletions kpops/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import kpops
from kpops import __version__
from kpops.api.file_type import KpopsFileType
from kpops.api.options import FilterType
from kpops.config import ENV_PREFIX, KpopsConfig
from kpops.utils.gen_schema import (
SchemaScope,
gen_config_schema,
gen_defaults_schema,
gen_pipeline_schema,
Expand Down Expand Up @@ -125,7 +125,7 @@ def init(
"""
)
def schema(
scope: SchemaScope = typer.Argument(
scope: KpopsFileType = typer.Argument(
...,
show_default=False,
help="""
Expand All @@ -141,17 +141,17 @@ def schema(
),
) -> None:
match scope:
case SchemaScope.PIPELINE:
case KpopsFileType.PIPELINE:
kpops_config = KpopsConfig.create(config)
gen_pipeline_schema(
kpops_config.components_module, include_stock_components
)
case SchemaScope.DEFAULTS:
case KpopsFileType.DEFAULTS:
kpops_config = KpopsConfig.create(config)
gen_defaults_schema(
kpops_config.components_module, include_stock_components
)
case SchemaScope.CONFIG:
case KpopsFileType.CONFIG:
gen_config_schema()


Expand Down
8 changes: 4 additions & 4 deletions kpops/utils/cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pydantic.fields import FieldInfo
from pydantic_core import PydanticUndefined

from kpops.api.kpops_resources import KpopsResources
from kpops.api.file_type import KpopsFileType
from kpops.config import KpopsConfig
from kpops.utils.docstring import describe_object
from kpops.utils.json import is_jsonable
Expand Down Expand Up @@ -73,6 +73,6 @@ def init_project(path: Path, conf_incl_opt: bool):
:param conf_incl_opt: Whether to include non-required settings
in the generated config file
"""
create_config(KpopsResources.CONFIG.value, path, conf_incl_opt)
Path(path / KpopsResources.PIPELINE.as_yaml_file()).touch(exist_ok=False)
Path(path / KpopsResources.DEFAULTS.as_yaml_file()).touch(exist_ok=False)
create_config(KpopsFileType.CONFIG.value, path, conf_incl_opt)
Path(path / KpopsFileType.PIPELINE.as_yaml_file()).touch(exist_ok=False)
Path(path / KpopsFileType.DEFAULTS.as_yaml_file()).touch(exist_ok=False)
7 changes: 0 additions & 7 deletions kpops/utils/gen_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
from abc import ABC
from collections.abc import Sequence
from enum import Enum
from typing import Annotated, Any, Literal, Union

from pydantic import (
Expand All @@ -28,12 +27,6 @@
from kpops.config import KpopsConfig


class SchemaScope(str, Enum):
PIPELINE = "pipeline"
DEFAULTS = "defaults"
CONFIG = "config"


class MultiComponentGenerateJsonSchema(GenerateJsonSchema): ...


Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/test_pipeline_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import pytest

from kpops.api.kpops_resources import KpopsResources
from kpops.api.file_type import KpopsFileType
from kpops.pipeline import PipelineGenerator
from kpops.utils.environment import ENV

PIPELINE_PATH = (
Path("./some/random/path/for/testing") / KpopsResources.PIPELINE.as_yaml_file()
Path("./some/random/path/for/testing") / KpopsFileType.PIPELINE.as_yaml_file()
)

PIPELINE_BASE_DIR = Path()
Expand Down
8 changes: 4 additions & 4 deletions tests/components/test_base_defaults_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pydantic
import pytest

from kpops.api.kpops_resources import KpopsResources
from kpops.api.file_type import KpopsFileType
from kpops.component_handlers import ComponentHandlers
from kpops.components.base_components.base_defaults_component import (
BaseDefaultsComponent,
Expand All @@ -17,9 +17,9 @@
from kpops.utils.environment import ENV
from tests.components import PIPELINE_BASE_DIR, RESOURCES_PATH

PIPELINE_YAML = KpopsResources.PIPELINE.as_yaml_file()
PIPELINE_YAML = KpopsFileType.PIPELINE.as_yaml_file()

DEFAULTS_YAML = KpopsResources.DEFAULTS.as_yaml_file()
DEFAULTS_YAML = KpopsFileType.DEFAULTS.as_yaml_file()


class Parent(BaseDefaultsComponent):
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_load_defaults_with_environment(
assert (
component_class.load_defaults(
RESOURCES_PATH
/ KpopsResources.DEFAULTS.as_yaml_file(prefix="development"),
/ KpopsFileType.DEFAULTS.as_yaml_file(prefix="_development"),
RESOURCES_PATH / DEFAULTS_YAML,
)
== defaults
Expand Down
8 changes: 4 additions & 4 deletions tests/pipeline/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

import kpops
from kpops.api.exception import ParsingException, ValidationError
from kpops.api.kpops_resources import KpopsResources
from kpops.api.file_type import KpopsFileType
from kpops.cli.main import FilterType, app
from kpops.components import KafkaSinkConnector, PipelineComponent

PIPELINE_YAML = KpopsResources.PIPELINE.as_yaml_file()
PIPELINE_YAML = KpopsFileType.PIPELINE.as_yaml_file()

runner = CliRunner()

Expand Down Expand Up @@ -177,7 +177,7 @@ def test_substitute_in_component_infinite_loop(self):
str(
RESOURCE_PATH
/ "component-type-substitution"
/ KpopsResources.PIPELINE.as_yaml_file(suffix="infinite_"),
/ KpopsFileType.PIPELINE.as_yaml_file(suffix="infinite_"),
),
],
catch_exceptions=False,
Expand Down Expand Up @@ -817,7 +817,7 @@ def test_substitution_in_resetter(self):
pipeline = kpops.generate(
RESOURCE_PATH
/ "resetter_values"
/ KpopsResources.PIPELINE.as_yaml_file(prefix="_connector_only"),
/ KpopsFileType.PIPELINE.as_yaml_file(prefix="_connector_only"),
)
assert isinstance(pipeline.components[0], KafkaSinkConnector)
assert pipeline.components[0].name == "es-sink-connector"
Expand Down

0 comments on commit 98f519b

Please sign in to comment.