Skip to content

Commit 6f6f778

Browse files
committed
feat: add option to sort before store
While storing workspace content on GitHub it is useful to have sorted content of YAML files. Therefore, the sort option is added. It is set to False because of backward compatibility. JIRA: PSDK-220 risk: low
1 parent 605e713 commit 6f6f778

File tree

16 files changed

+100
-59
lines changed

16 files changed

+100
-59
lines changed

docs/content/en/latest/workspace-content/analytics-model/store_analytics_model_to_disk.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ weight: 131
55
superheading: "catalog_workspace_content."
66
---
77

8-
``store_analytics_model_to_disk(workspace_id: str, path: Path = Path.cwd())``
8+
``store_analytics_model_to_disk(workspace_id: str, path: Path = Path.cwd(), exclude: Optional[list[str]] = None, sort: bool = False)``
99

1010
Stores analytics model for a given workspace in directory hierarchy.This method does not tie the declarative analytics model to the workspace and organization, thus it is recommended for migration between workspaces. If you want to backup analytics model between workspaces or organizations, use [store_analytics_model_to_disk](../store_analytics_model_to_disk/).
1111

@@ -31,6 +31,12 @@ Workspace identification string e.g. "demo"
3131
{{< parameter p_name="path" p_type="Optional[Path]" >}}
3232
Path to the root of the layout directory. Defaults to Path.cwd().
3333
{{< /parameter >}}
34+
{{< parameter p_name="exclude" p_type=" Optional[list[str]]" >}}
35+
Defines properties which should not be included in the result. E.g.: ["ACTIVITY_INFO"] – refers to createdBy, etc. Default is None.
36+
{{< /parameter >}}
37+
{{< parameter p_name="sort" p_type="bool" >}}
38+
Flag if the output should be sorted before storing to disk. Default is False.
39+
{{< /parameter >}}
3440
{{% /parameters-block %}}
3541

3642
{{% parameters-block title="Returns" None="yes" %}}

docs/content/en/latest/workspace-content/logical-data-model/store_ldm_to_disk.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ superheading: "catalog_workspace_content."
66
---
77

88

9-
``store_ldm_to_disk(workspace_id: str, path: Path = Path.cwd())``
9+
``store_ldm_to_disk(workspace_id: str, path: Path = Path.cwd(), sort: bool = False)``
1010

1111
Stores the declarative logical data model for a given workspace in directory hierarchy. This method does not tie the LDM to the workspace and organization, thus it is recommended for migration between organizations. If you want to backup LDM use [store_declarative_ldm](../store_declarative_ldm/).
1212

@@ -26,6 +26,9 @@ Workspace identification string e.g. "demo"
2626
{{< parameter p_name="path" p_type="Optional[Path]" >}}
2727
Path to the root of the layout directory. Defaults to Path.cwd().
2828
{{< /parameter >}}
29+
{{< parameter p_name="sort" p_type="bool" >}}
30+
Flag if the output should be sorted before storing to disk. Default is False.
31+
{{< /parameter >}}
2932
{{% /parameters-block %}}
3033

3134
{{% parameters-block title="Returns" None="yes" %}}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ def client_class() -> type[DeclarativeDataSources]:
110110
def data_sources_folder(layout_organization_folder: Path) -> Path:
111111
return layout_organization_folder / LAYOUT_DATA_SOURCES_DIR
112112

113-
def store_to_disk(self, layout_organization_folder: Path) -> None:
113+
def store_to_disk(self, layout_organization_folder: Path, sort: bool = False) -> None:
114114
data_sources_folder = self.data_sources_folder(layout_organization_folder)
115115
create_directory(data_sources_folder)
116116
for data_source in self.data_sources:
117-
data_source.store_to_disk(data_sources_folder)
117+
data_source.store_to_disk(data_sources_folder, sort=sort)
118118

119119
@classmethod
120120
def load_from_disk(cls, layout_organization_folder: Path) -> CatalogDeclarativeDataSources:
@@ -201,12 +201,12 @@ def to_api(
201201
dictionary["client_secret"] = client_secret
202202
return self.client_class().from_dict(dictionary)
203203

204-
def store_to_disk(self, data_sources_folder: Path) -> None:
204+
def store_to_disk(self, data_sources_folder: Path, sort: bool = False) -> None:
205205
data_source_folder = self.data_source_folder(data_sources_folder, self.id)
206206
file_path = data_source_folder / f"{self.id}.yaml"
207207
data_source_dict = self.to_api().to_dict(camel_case=True)
208208

209-
write_layout_to_file(file_path, data_source_dict)
209+
write_layout_to_file(file_path, data_source_dict, sort=sort)
210210

211211
@classmethod
212212
def load_from_disk(cls, data_sources_folder: Path, data_source_id: str) -> CatalogDeclarativeDataSource:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class CatalogDeclarativeTable(Base):
2525
def client_class() -> builtins.type[DeclarativeTable]:
2626
return DeclarativeTable
2727

28-
def store_to_disk(self, pdm_folder: Path) -> None:
28+
def store_to_disk(self, pdm_folder: Path, sort: bool = False) -> None:
2929
table_dict = self.to_api().to_dict(camel_case=True)
3030
table_file_path = pdm_folder / f"{self.id}.yaml"
31-
write_layout_to_file(table_file_path, table_dict)
31+
write_layout_to_file(table_file_path, table_dict, sort=sort)
3232

3333
@classmethod
3434
def load_from_disk(cls, table_file_path: Path) -> CatalogDeclarativeTable:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def load_from_disk(cls, layout_organization_folder: Path) -> CatalogDeclarativeU
3434
users = [CatalogDeclarativeUser.from_dict(record, camel_case=True) for record in data]
3535
return cls(users=users)
3636

37-
def store_to_disk(self, layout_organization_folder: Path) -> None:
37+
def store_to_disk(self, layout_organization_folder: Path, sort: bool = False) -> None:
3838
users_directory = layout_organization_folder / LAYOUT_USERS_DIR
3939
users_file = users_directory / LAYOUT_USERS_FILE
4040
create_directory(users_directory)
4141
users = [user.to_dict(camel_case=True) for user in self.users]
42-
write_layout_to_file(users_file, users)
42+
write_layout_to_file(users_file, users, sort=sort)
4343

4444

4545
@attr.s(auto_attribs=True, kw_only=True)

gooddata-sdk/gooddata_sdk/catalog/user/declarative_model/user_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ def load_from_disk(cls, layout_organization_folder: Path) -> CatalogDeclarativeU
3333
user_groups = [CatalogDeclarativeUserGroup.from_dict(record, camel_case=True) for record in data]
3434
return cls(user_groups=user_groups)
3535

36-
def store_to_disk(self, layout_organization_folder: Path) -> None:
36+
def store_to_disk(self, layout_organization_folder: Path, sort: bool = False) -> None:
3737
user_groups_directory = layout_organization_folder / LAYOUT_USER_GROUPS_DIR
3838
user_groups_file = user_groups_directory / LAYOUT_USER_GROUPS_FILE
3939
create_directory(user_groups_directory)
4040
user_groups = [user_group.to_dict(camel_case=True) for user_group in self.user_groups]
41-
write_layout_to_file(user_groups_file, user_groups)
41+
write_layout_to_file(user_groups_file, user_groups, sort=sort)
4242

4343

4444
@attr.s(auto_attribs=True, kw_only=True)

gooddata-sdk/gooddata_sdk/catalog/workspace/content_service.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def load_and_put_declarative_ldm(
358358
declarative_ldm = self.load_declarative_ldm(workspace_id, layout_root_path)
359359
self.put_declarative_ldm(workspace_id, declarative_ldm, validator, standalone_copy)
360360

361-
def store_ldm_to_disk(self, workspace_id: str, path: Path = Path.cwd()) -> None:
361+
def store_ldm_to_disk(self, workspace_id: str, path: Path = Path.cwd(), sort: bool = False) -> None:
362362
"""Store declarative logical data model for a given workspace in directory hierarchy.
363363
This method does not tie the LDM to the workspace and organization, thus it is recommended
364364
for migration between organizations. If you want to backup LDM use store_declarative_ldm.
@@ -368,11 +368,13 @@ def store_ldm_to_disk(self, workspace_id: str, path: Path = Path.cwd()) -> None:
368368
Workspace identification string e.g. "demo"
369369
path (Path, optional):
370370
Path to the root of the layout directory. Defaults to Path.cwd().
371+
sort (bool, optional):
372+
Flag if the output should be sorted before storing to disk. Default is False.
371373
372374
Returns:
373375
None
374376
"""
375-
self.get_declarative_ldm(workspace_id).store_to_disk(path)
377+
self.get_declarative_ldm(workspace_id).store_to_disk(path, sort=sort)
376378

377379
@staticmethod
378380
def load_ldm_from_disk(path: Path = Path.cwd()) -> CatalogDeclarativeModel:
@@ -479,7 +481,7 @@ def load_and_put_declarative_analytics_model(self, workspace_id: str, layout_roo
479481
self.put_declarative_analytics_model(workspace_id, declarative_analytics_model)
480482

481483
def store_analytics_model_to_disk(
482-
self, workspace_id: str, path: Path = Path.cwd(), exclude: Optional[list[str]] = None
484+
self, workspace_id: str, path: Path = Path.cwd(), exclude: Optional[list[str]] = None, sort: bool = False
483485
) -> None:
484486
"""Store analytics model for a given workspace in directory hierarchy.This method does not tie the declarative
485487
analytics model to the workspace and organization, thus it is recommended for migration between workspaces.
@@ -491,12 +493,14 @@ def store_analytics_model_to_disk(
491493
path (Path, optional):
492494
Path to the root of the layout directory. Defaults to Path.cwd().
493495
exclude (Optional[list[str]]):
494-
Defines properties which should not be included in the payload. E.g.: ["ACTIVITY_INFO"]
496+
Defines properties which should not be included in the result. E.g.: ["ACTIVITY_INFO"] – refers to createdBy, etc. Default is None.
497+
sort (bool, optional):
498+
Flag if the output should be sorted before storing to disk. Default is False.
495499
496500
Returns:
497501
None
498502
"""
499-
self.get_declarative_analytics_model(workspace_id, exclude).store_to_disk(path)
503+
self.get_declarative_analytics_model(workspace_id, exclude).store_to_disk(path, sort=sort)
500504

501505
@staticmethod
502506
def load_analytics_model_from_disk(path: Path = Path.cwd()) -> CatalogDeclarativeAnalytics:

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class CatalogDeclarativeAnalytics(Base):
5858
def client_class() -> type[DeclarativeAnalytics]:
5959
return DeclarativeAnalytics
6060

61-
def store_to_disk(self, workspace_folder: Path) -> None:
61+
def store_to_disk(self, workspace_folder: Path, sort: bool = False) -> None:
6262
if self.analytics is not None:
63-
self.analytics.store_to_disk(workspace_folder)
63+
self.analytics.store_to_disk(workspace_folder, sort=sort)
6464

6565
@classmethod
6666
def load_from_disk(cls, workspace_folder: Path) -> CatalogDeclarativeAnalytics:
@@ -137,7 +137,7 @@ def get_export_definition_dif(analytics_model_folder: Path) -> Path:
137137
create_directory(folder)
138138
return folder
139139

140-
def store_to_disk(self, workspace_folder: Path) -> None:
140+
def store_to_disk(self, workspace_folder: Path, sort: bool = False) -> None:
141141
analytics_model_folder = self.get_analytics_model_folder(workspace_folder)
142142

143143
analytical_dashboards_folder = self.get_analytical_dashboards_folder(analytics_model_folder)
@@ -150,28 +150,28 @@ def store_to_disk(self, workspace_folder: Path) -> None:
150150
export_definition_folder = self.get_export_definition_dif(analytical_dashboards_folder)
151151

152152
for analytical_dashboard in self.analytical_dashboards:
153-
analytical_dashboard.store_to_disk(analytical_dashboards_folder)
153+
analytical_dashboard.store_to_disk(analytical_dashboards_folder, sort=sort)
154154

155155
for analytical_dashboard_extension in self.analytical_dashboard_extensions:
156-
analytical_dashboard_extension.store_to_disk(analytical_dashboard_extensions_folder)
156+
analytical_dashboard_extension.store_to_disk(analytical_dashboard_extensions_folder, sort=sort)
157157

158158
for dashboard_plugin in self.dashboard_plugins:
159-
dashboard_plugin.store_to_disk(dashboard_plugins_folder)
159+
dashboard_plugin.store_to_disk(dashboard_plugins_folder, sort=sort)
160160

161161
for filter_context in self.filter_contexts:
162-
filter_context.store_to_disk(filter_contexts_folder)
162+
filter_context.store_to_disk(filter_contexts_folder, sort=sort)
163163

164164
for metric in self.metrics:
165-
metric.store_to_disk(metrics_folder)
165+
metric.store_to_disk(metrics_folder, sort=sort)
166166

167167
for visualization_object in self.visualization_objects:
168-
visualization_object.store_to_disk(visualization_objects_folder)
168+
visualization_object.store_to_disk(visualization_objects_folder, sort=sort)
169169

170170
for attribute_hierarchy in self.attribute_hierarchies:
171-
attribute_hierarchy.store_to_disk(attribute_hierarchy_folder)
171+
attribute_hierarchy.store_to_disk(attribute_hierarchy_folder, sort=sort)
172172

173173
for export_definition in self.export_definitions:
174-
export_definition.store_to_disk(export_definition_folder)
174+
export_definition.store_to_disk(export_definition_folder, sort=sort)
175175

176176
@classmethod
177177
def load_from_disk(cls, workspace_folder: Path) -> CatalogDeclarativeAnalyticsLayer:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
class CatalogAnalyticsObjectBase(Base):
1616
id: str
1717

18-
def store_to_disk(self, analytics_folder: Path) -> None:
18+
def store_to_disk(self, analytics_folder: Path, sort: bool = False) -> None:
1919
analytics_file = analytics_folder / f"{self.id}.yaml"
20-
write_layout_to_file(analytics_file, self.to_api().to_dict(camel_case=True))
20+
write_layout_to_file(analytics_file, self.to_api().to_dict(camel_case=True), sort=sort)
2121

2222
@classmethod
2323
def load_from_disk(cls: type[T], analytics_file: Path) -> T:

gooddata-sdk/gooddata_sdk/catalog/workspace/declarative_model/workspace/logical_model/dataset/dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ class CatalogDeclarativeDataset(Base):
5353
def client_class() -> type[DeclarativeDataset]:
5454
return DeclarativeDataset
5555

56-
def store_to_disk(self, datasets_folder: Path) -> None:
56+
def store_to_disk(self, datasets_folder: Path, sort: bool = False) -> None:
5757
dataset_file = datasets_folder / f"{self.id}.yaml"
58-
write_layout_to_file(dataset_file, self.to_api().to_dict(camel_case=True))
58+
write_layout_to_file(dataset_file, self.to_api().to_dict(camel_case=True), sort=sort)
5959

6060
@classmethod
6161
def load_from_disk(cls, dataset_file: Path) -> CatalogDeclarativeDataset:

0 commit comments

Comments
 (0)