From a61de1b1dc93a9cbcd138f439355a2328cb432f5 Mon Sep 17 00:00:00 2001 From: Salomon Popp Date: Tue, 9 Jul 2024 09:32:29 +0200 Subject: [PATCH 1/3] Improve dataclass instance check (#507) --- kpops/components/base_components/base_defaults_component.py | 5 +++-- kpops/utils/dataclasses.py | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 kpops/utils/dataclasses.py diff --git a/kpops/components/base_components/base_defaults_component.py b/kpops/components/base_components/base_defaults_component.py index f63eaf5c2..3ad8ac894 100644 --- a/kpops/components/base_components/base_defaults_component.py +++ b/kpops/components/base_components/base_defaults_component.py @@ -4,7 +4,7 @@ import logging from abc import ABC from collections.abc import Hashable, Sequence -from dataclasses import asdict, is_dataclass +from dataclasses import asdict from functools import cached_property from pathlib import Path from typing import Any, TypeVar @@ -23,6 +23,7 @@ from kpops.component_handlers import ComponentHandlers from kpops.config import KpopsConfig from kpops.utils import cached_classproperty +from kpops.utils.dataclasses import is_dataclass_instance from kpops.utils.dict_ops import ( generate_substitution, update_nested, @@ -181,7 +182,7 @@ def extend_with_defaults(cls, config: KpopsConfig, **kwargs: Any) -> dict[str, A for k, v in kwargs.items(): if isinstance(v, pydantic.BaseModel): kwargs[k] = v.model_dump(exclude_unset=True) - elif is_dataclass(v): + elif is_dataclass_instance(v): kwargs[k] = asdict(v) defaults_file_paths_ = get_defaults_file_paths( diff --git a/kpops/utils/dataclasses.py b/kpops/utils/dataclasses.py new file mode 100644 index 000000000..16db70d94 --- /dev/null +++ b/kpops/utils/dataclasses.py @@ -0,0 +1,5 @@ +from dataclasses import is_dataclass + + +def is_dataclass_instance(obj: object) -> bool: + return is_dataclass(obj) and not isinstance(obj, type) From ae894d1b06fa84122aaca9dfb60b826ba280d87c Mon Sep 17 00:00:00 2001 From: Salomon Popp Date: Tue, 9 Jul 2024 16:48:12 +0200 Subject: [PATCH 2/3] Delete ignored keys from diff (#510) --- kpops/utils/dict_differ.py | 28 ++++++++++++++++++++++++---- tests/utils/test_diff.py | 2 -- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/kpops/utils/dict_differ.py b/kpops/utils/dict_differ.py index 1c3dbdeb7..9f1ca97e2 100644 --- a/kpops/utils/dict_differ.py +++ b/kpops/utils/dict_differ.py @@ -1,10 +1,10 @@ from __future__ import annotations -from collections.abc import Mapping +from collections.abc import Mapping, MutableMapping from dataclasses import dataclass from difflib import Differ from enum import Enum -from typing import TYPE_CHECKING, Generic, TypeVar +from typing import TYPE_CHECKING, Any, Generic, TypeVar import typer import yaml @@ -79,8 +79,28 @@ def __find_changed_key(key_1: list[str] | str, key_2: str = "") -> str: return f"{key_1}.{key_2}" -def render_diff(d1: Mapping, d2: Mapping, ignore: set[str] | None = None) -> str | None: - differences = list(diff(d1, d2, ignore=ignore)) +def render_diff( + d1: MutableMapping[str, Any], + d2: MutableMapping[str, Any], + ignore: set[str] | None = None, +) -> str | None: + def del_ignored_keys(d: MutableMapping[str, Any]) -> None: + """Delete key to be ignored, dictionary is modified in-place.""" + if ignore: + for i in ignore: + key_path = i.split(".") + nested = d + try: + for key in key_path[:-1]: + nested = nested[key] + del nested[key_path[-1]] + except KeyError: + continue + + del_ignored_keys(d1) + del_ignored_keys(d2) + + differences = list(diff(d1, d2)) if not differences: return None diff --git a/tests/utils/test_diff.py b/tests/utils/test_diff.py index f2ffeac88..8a6e5f2b7 100644 --- a/tests/utils/test_diff.py +++ b/tests/utils/test_diff.py @@ -25,7 +25,6 @@ {"a": 1, "b": 2, "c": 3}, {"a": 2, "d": 1}, {"a"}, - " a: 1\n" "\x1b[32m+ d: 1\n" "\x1b[0m\x1b[31m- b: 2\n" "\x1b[0m\x1b[31m- c: 3\n" @@ -36,7 +35,6 @@ {"a": {"a": 9, "b": 8}, "d": 1}, {"a.a"}, " a:\n" - " a: 1\n" "\x1b[31m- b: 2\n" "\x1b[0m\x1b[33m? ^\n" "\x1b[0m\x1b[32m+ b: 8\n" From 9d37a50db3fd07e50b484152721f4a63783971a8 Mon Sep 17 00:00:00 2001 From: bakdata-bots Date: Tue, 9 Jul 2024 14:49:57 +0000 Subject: [PATCH 3/3] =?UTF-8?q?Bump=20version=206.0.2=20=E2=86=92=206.1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs/user/changelog.md | 18 ++++++++++++++++++ kpops/__init__.py | 2 +- pyproject.toml | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/docs/user/changelog.md b/docs/docs/user/changelog.md index 4d6909f1d..ac88d6bf6 100644 --- a/docs/docs/user/changelog.md +++ b/docs/docs/user/changelog.md @@ -1,4 +1,22 @@ # Changelog +## [6.1.0](https://github.com/bakdata/kpops/releases/tag/6.1.0) - Release Date: [2024-07-09] + +### 🚀 Features + +- Add image tag field to streams-bootstrap app values - [#499](https://github.com/bakdata/kpops/pull/499) + +- Delete ignored keys from diff - [#510](https://github.com/bakdata/kpops/pull/510) + + +### 🏭 Refactor + +- Improve dataclass instance check - [#507](https://github.com/bakdata/kpops/pull/507) + + + + + + ## [6.0.2](https://github.com/bakdata/kpops/releases/tag/6.0.2) - Release Date: [2024-07-04] ### 📝 Documentation diff --git a/kpops/__init__.py b/kpops/__init__.py index 22aebfa50..6aa79f94f 100644 --- a/kpops/__init__.py +++ b/kpops/__init__.py @@ -1,4 +1,4 @@ -__version__ = "6.0.2" +__version__ = "6.1.0" # export public API functions from kpops.api import clean, deploy, destroy, generate, init, manifest, reset diff --git a/pyproject.toml b/pyproject.toml index f84f7a43e..e8bb14707 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "kpops" -version = "6.0.2" +version = "6.1.0" description = "KPOps is a tool to deploy Kafka pipelines to Kubernetes" authors = ["bakdata "] license = "MIT"