From 0868767d3e6289a15d65aa14e057a1f4ea397d05 Mon Sep 17 00:00:00 2001 From: Callum McCann Date: Wed, 17 May 2023 10:39:54 -0500 Subject: [PATCH 1/3] First attempt at version with failing test --- .changes/unreleased/Features-20230517-103947.yaml | 6 ++++++ .../implementations/semantic_manifest.py | 10 ++++++++++ .../protocols/semantic_manifest.py | 7 +++++++ pyproject.toml | 1 + tests/parsing/test_semantic_manifest_parsing.py | 15 +++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 .changes/unreleased/Features-20230517-103947.yaml create mode 100644 tests/parsing/test_semantic_manifest_parsing.py diff --git a/.changes/unreleased/Features-20230517-103947.yaml b/.changes/unreleased/Features-20230517-103947.yaml new file mode 100644 index 00000000..6642837e --- /dev/null +++ b/.changes/unreleased/Features-20230517-103947.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Adding DSI version number to semantic manifest +time: 2023-05-17T10:39:47.542969-05:00 +custom: + Author: callum-mcdata + Issue: "30" diff --git a/dbt_semantic_interfaces/implementations/semantic_manifest.py b/dbt_semantic_interfaces/implementations/semantic_manifest.py index 469f11d7..b0cd4a1d 100644 --- a/dbt_semantic_interfaces/implementations/semantic_manifest.py +++ b/dbt_semantic_interfaces/implementations/semantic_manifest.py @@ -1,5 +1,7 @@ from typing import List +from importlib_metadata import PackageNotFoundError, version + from dbt_semantic_interfaces.implementations.base import HashableBaseModel from dbt_semantic_interfaces.implementations.metric import Metric from dbt_semantic_interfaces.implementations.semantic_model import SemanticModel @@ -10,3 +12,11 @@ class SemanticManifest(HashableBaseModel): semantic_models: List[SemanticModel] metrics: List[Metric] + + @property + def interfaces_version(self) -> str: + """Returns the version of the dbt_semantic_interfaces package that generated this manifest.""" + try: + return version("dbt_semantic_interfaces") + except PackageNotFoundError: + return "dbt_semantic_interfaces is not installed" diff --git a/dbt_semantic_interfaces/protocols/semantic_manifest.py b/dbt_semantic_interfaces/protocols/semantic_manifest.py index 11de822d..d3cc9efb 100644 --- a/dbt_semantic_interfaces/protocols/semantic_manifest.py +++ b/dbt_semantic_interfaces/protocols/semantic_manifest.py @@ -1,3 +1,4 @@ +from abc import abstractmethod from typing import List, Protocol from dbt_semantic_interfaces.protocols.metric import Metric @@ -9,3 +10,9 @@ class SemanticManifest(Protocol): semantic_models: List[SemanticModel] metrics: List[Metric] + + @property + @abstractmethod + def interfaces_version(self) -> str: + """Returns the version of the dbt_semantic_interfaces package that generated this manifest.""" + ... diff --git a/pyproject.toml b/pyproject.toml index 0548eaa6..a51952e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ dependencies = [ "Jinja2==3.1.2", "click>=7.1.2", "python-dateutil==2.8.2", + "importlib_metadata==6.6.0" ] [build-system] diff --git a/tests/parsing/test_semantic_manifest_parsing.py b/tests/parsing/test_semantic_manifest_parsing.py new file mode 100644 index 00000000..d177126e --- /dev/null +++ b/tests/parsing/test_semantic_manifest_parsing.py @@ -0,0 +1,15 @@ +from importlib_metadata import version + +from dbt_semantic_interfaces.objects.semantic_manifest import SemanticManifest + + +def test_interfaces_version() -> None: + """Test that the interfaces_version property returns the installed version of dbt_semantic_interfaces.""" + semantic_manifest = SemanticManifest( + semantic_models=[], + metrics=[], + ) + + # get the actual installed version + installed_version = version("dbt_semantic_interfaces") + assert semantic_manifest.interfaces_version == installed_version From bbeb8db98c29beb0c2edd1d66beca91f4852d691 Mon Sep 17 00:00:00 2001 From: Callum McCann Date: Wed, 17 May 2023 14:56:53 -0500 Subject: [PATCH 2/3] Make `interfaces_version` a direct attribute `interfaces_version` has to be a direct attribute of the `SemanticManifest` for deserialization to work properly. With it being a direct attribute, we had to begin using the pydantic validator to ensure the version gets set on `SemanticManifest` instantiation. Note: Callum McCann authored this commit, but I (Quigley Malcolm) have updated the commit message. --- .../implementations/semantic_manifest.py | 16 +++++++++------- .../protocols/semantic_manifest.py | 8 +------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/dbt_semantic_interfaces/implementations/semantic_manifest.py b/dbt_semantic_interfaces/implementations/semantic_manifest.py index b0cd4a1d..7688328d 100644 --- a/dbt_semantic_interfaces/implementations/semantic_manifest.py +++ b/dbt_semantic_interfaces/implementations/semantic_manifest.py @@ -1,6 +1,7 @@ from typing import List -from importlib_metadata import PackageNotFoundError, version +from importlib_metadata import version +from pydantic import validator from dbt_semantic_interfaces.implementations.base import HashableBaseModel from dbt_semantic_interfaces.implementations.metric import Metric @@ -12,11 +13,12 @@ class SemanticManifest(HashableBaseModel): semantic_models: List[SemanticModel] metrics: List[Metric] + interfaces_version: str = "" - @property - def interfaces_version(self) -> str: + @validator("interfaces_version", always=True) + @classmethod + def __create_default_interfaces_version(cls, value: str) -> str: # type: ignore[misc] """Returns the version of the dbt_semantic_interfaces package that generated this manifest.""" - try: - return version("dbt_semantic_interfaces") - except PackageNotFoundError: - return "dbt_semantic_interfaces is not installed" + if value: + return value + return version("dbt_semantic_interfaces") diff --git a/dbt_semantic_interfaces/protocols/semantic_manifest.py b/dbt_semantic_interfaces/protocols/semantic_manifest.py index d3cc9efb..e76f2b7c 100644 --- a/dbt_semantic_interfaces/protocols/semantic_manifest.py +++ b/dbt_semantic_interfaces/protocols/semantic_manifest.py @@ -1,4 +1,3 @@ -from abc import abstractmethod from typing import List, Protocol from dbt_semantic_interfaces.protocols.metric import Metric @@ -10,9 +9,4 @@ class SemanticManifest(Protocol): semantic_models: List[SemanticModel] metrics: List[Metric] - - @property - @abstractmethod - def interfaces_version(self) -> str: - """Returns the version of the dbt_semantic_interfaces package that generated this manifest.""" - ... + interfaces_version: str From cfd19125e92990043e70bc0338c1946120561973 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Fri, 19 May 2023 17:01:51 -0700 Subject: [PATCH 3/3] Move testing of implemented `SemanticManifest`'s `interfaces_version` setting --- .../test_semantic_manifest.py} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename tests/{parsing/test_semantic_manifest_parsing.py => implementations/test_semantic_manifest.py} (75%) diff --git a/tests/parsing/test_semantic_manifest_parsing.py b/tests/implementations/test_semantic_manifest.py similarity index 75% rename from tests/parsing/test_semantic_manifest_parsing.py rename to tests/implementations/test_semantic_manifest.py index d177126e..75e6389c 100644 --- a/tests/parsing/test_semantic_manifest_parsing.py +++ b/tests/implementations/test_semantic_manifest.py @@ -1,9 +1,9 @@ from importlib_metadata import version -from dbt_semantic_interfaces.objects.semantic_manifest import SemanticManifest +from dbt_semantic_interfaces.implementations.semantic_manifest import SemanticManifest -def test_interfaces_version() -> None: +def test_interfaces_version_matches() -> None: """Test that the interfaces_version property returns the installed version of dbt_semantic_interfaces.""" semantic_manifest = SemanticManifest( semantic_models=[],