Skip to content

Commit 5e1c227

Browse files
committed
NAS-3695 minor fixes
* all classes participated in load_from_disk for data sources returns their instance in the process. * for generate_logical_model set generate_ldm_request default (like for generating_pdm) * for kwargs CatalogAnalyticsBase added is not None check
1 parent 0da23e6 commit 5e1c227

7 files changed

Lines changed: 51 additions & 16 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
.venv
66
test_clients.py
77
gooddata-sdk/tests/catalog/store
8+
.DS_Store

MAINTENANCE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Create pull request with the latest commit with bumped versions
77
* Ask for merge of pull request. Once it is merged:
88
* Checkout latest master tag it vX.Y.Z
9-
* Push the tag to the gooddata/gooddata-python-sdk repository (e.g. `git push <remote> v.X.Y.Z`)
9+
* Push the tag to the gooddata/gooddata-python-sdk repository (e.g. `git push <remote> vX.Y.Z`)
1010

1111
### Errors that may appear
1212

gooddata-sdk/gooddata_sdk/catalog/data_source/declarative_model/data_source.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def load_from_disk(cls, layout_organization_folder: Path) -> CatalogDeclarativeD
6969
data_sources = []
7070
for data_source_id in data_source_ids:
7171
data_sources.append(CatalogDeclarativeDataSource.load_from_disk(data_sources_folder, data_source_id))
72-
return cls.from_dict({"dataSources": data_sources})
72+
return cls(data_sources=data_sources)
7373

7474
def __eq__(self, other: object) -> bool:
7575
if not isinstance(other, CatalogDeclarativeDataSources):
@@ -178,15 +178,29 @@ def store_to_disk(self, data_sources_folder: Path) -> None:
178178
if self.pdm is not None:
179179
self.pdm.store_to_disk(data_source_folder)
180180

181-
@staticmethod
182-
def load_from_disk(data_sources_folder: Path, data_source_id: str) -> dict:
181+
@classmethod
182+
def load_from_disk(cls, data_sources_folder: Path, data_source_id: str) -> CatalogDeclarativeDataSource:
183183
data_source_folder = data_sources_folder / data_source_id
184184
data_source_file_path = data_source_folder / f"{data_source_id}.yaml"
185185
pdm = CatalogDeclarativeTables.load_from_disk(data_source_folder)
186-
data_source = read_layout_from_file(data_source_file_path)
187-
data_source["pdm"] = pdm
186+
data_source_dict = read_layout_from_file(data_source_file_path)
187+
data_source = CatalogDeclarativeDataSource.from_dict(data_source_dict)
188+
data_source.pdm = pdm
188189
return data_source
189190

191+
@classmethod
192+
def from_dict(cls, data: dict[str, Any], camel_case: bool = True) -> CatalogDeclarativeDataSource:
193+
"""
194+
:param data: Data loaded for example from the file.
195+
:param camel_case: True if the variable names in the input
196+
data are serialized names as specified in the OpenAPI document.
197+
False if the variables names in the input data are python
198+
variable names in PEP-8 snake case.
199+
:return: CatalogDeclarativeDataSource object.
200+
"""
201+
declarative_data_source = DeclarativeDataSource.from_dict(data, camel_case)
202+
return cls.from_api(declarative_data_source)
203+
190204
def __eq__(self, other: object) -> bool:
191205
if not isinstance(other, CatalogDeclarativeDataSource):
192206
return False

gooddata-sdk/gooddata_sdk/catalog/data_source/declarative_model/physical_model/pdm.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from gooddata_metadata_client.model.declarative_tables import DeclarativeTables
88
from gooddata_sdk.catalog.data_source.declarative_model.physical_model.table import CatalogDeclarativeTable
9-
from gooddata_sdk.utils import create_directory, read_layout_from_file
9+
from gooddata_sdk.utils import create_directory
1010

1111
LAYOUT_PDM_DIR = "pdm"
1212

@@ -49,14 +49,14 @@ def from_dict(cls, data: dict[str, Any], camel_case: bool = True) -> CatalogDecl
4949
declarative_data_sources = DeclarativeTables.from_dict(data, camel_case)
5050
return cls.from_api(declarative_data_sources)
5151

52-
@staticmethod
53-
def load_from_disk(data_source_folder: Path) -> dict:
52+
@classmethod
53+
def load_from_disk(cls, data_source_folder: Path) -> CatalogDeclarativeTables:
5454
pdm_folder = get_pdm_folder(data_source_folder)
5555
table_files = sorted([p for p in pdm_folder.glob("*.yaml")])
5656
tables = []
5757
for table_file in table_files:
58-
tables.append(read_layout_from_file(table_file))
59-
return {"tables": tables}
58+
tables.append(CatalogDeclarativeTable.load_from_disk(table_file))
59+
return cls(tables=tables)
6060

6161
def __eq__(self, other: object) -> bool:
6262
if not isinstance(other, CatalogDeclarativeTables):

gooddata-sdk/gooddata_sdk/catalog/data_source/declarative_model/physical_model/table.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from gooddata_metadata_client.model.declarative_table import DeclarativeTable
88
from gooddata_sdk.catalog.data_source.declarative_model.physical_model.column import CatalogDeclarativeColumn
99
from gooddata_sdk.catalog.entity import CatalogTypeEntity
10-
from gooddata_sdk.utils import write_layout_to_file
10+
from gooddata_sdk.utils import read_layout_from_file, write_layout_to_file
1111

1212

1313
class CatalogDeclarativeTable(CatalogTypeEntity):
@@ -41,6 +41,24 @@ def store_to_disk(self, pdm_folder: Path) -> None:
4141
table_file_path = pdm_folder / f"{self.id}.yaml"
4242
write_layout_to_file(table_file_path, table_dict)
4343

44+
@classmethod
45+
def load_from_disk(cls, table_file_path: Path) -> CatalogDeclarativeTable:
46+
table_data = read_layout_from_file(table_file_path)
47+
return CatalogDeclarativeTable.from_dict(table_data)
48+
49+
@classmethod
50+
def from_dict(cls, data: dict[str, Any], camel_case: bool = True) -> CatalogDeclarativeTable:
51+
"""
52+
:param data: Data loaded for example from the file.
53+
:param camel_case: True if the variable names in the input
54+
data are serialized names as specified in the OpenAPI document.
55+
False if the variables names in the input data are python
56+
variable names in PEP-8 snake case.
57+
:return: CatalogDeclarativeTable object.
58+
"""
59+
declarative_table = DeclarativeTable.from_dict(data, camel_case)
60+
return cls.from_api(declarative_table)
61+
4462
def __eq__(self, other: object) -> bool:
4563
if not isinstance(other, CatalogDeclarativeTable):
4664
return False

gooddata-sdk/gooddata_sdk/catalog/data_source/service.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ def patch_data_source_attributes(self, data_source_id: str, attributes: dict) ->
8282
)
8383

8484
def generate_logical_model(
85-
self, data_source_id: str, generate_ldm_request: CatalogGenerateLdmRequest
85+
self,
86+
data_source_id: str,
87+
generate_ldm_request: CatalogGenerateLdmRequest = CatalogGenerateLdmRequest(separator="__", wdf_prefix="wdf"),
8688
) -> CatalogDeclarativeModel:
8789
return CatalogDeclarativeModel.from_api(
8890
self._actions_api.generate_logical_model(data_source_id, generate_ldm_request.to_api())
@@ -207,7 +209,7 @@ def load_declarative_pdm(
207209
self, data_source_id: str, layout_root_path: Path = Path.cwd()
208210
) -> CatalogDeclarativeTables:
209211
data_source_folder = self.data_source_folder(data_source_id, layout_root_path)
210-
return CatalogDeclarativeTables.from_dict(CatalogDeclarativeTables.load_from_disk(data_source_folder))
212+
return CatalogDeclarativeTables.load_from_disk(data_source_folder)
211213

212214
def load_and_put_declarative_pdm(self, data_source_id: str, layout_root_path: Path = Path.cwd()) -> None:
213215
self.put_declarative_pdm(data_source_id, self.load_declarative_pdm(data_source_id, layout_root_path))

gooddata-sdk/gooddata_sdk/catalog/workspace/declarative_model/workspace/analytics_model/analytics_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ def __repr__(self) -> str:
289289

290290
def get_kwargs(self) -> dict[str, Any]:
291291
kwargs: dict[str, Any] = dict()
292-
if self.description:
292+
if self.description is not None:
293293
kwargs["description"] = self.description
294-
if self.tags:
294+
if self.tags is not None:
295295
kwargs["tags"] = self.tags
296296
return kwargs
297297

0 commit comments

Comments
 (0)