gooddata-code-convertors 11.28.0a13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gooddata_code_convertors/__init__.py +118 -0
- gooddata_code_convertors/_data/convertors.wasm +0 -0
- gooddata_code_convertors/_wasm_runtime.py +132 -0
- gooddata_code_convertors/py.typed +0 -0
- gooddata_code_convertors-11.28.0a13.dist-info/METADATA +77 -0
- gooddata_code_convertors-11.28.0a13.dist-info/RECORD +8 -0
- gooddata_code_convertors-11.28.0a13.dist-info/WHEEL +4 -0
- gooddata_code_convertors-11.28.0a13.dist-info/licenses/LICENSE +7 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# (C) 2026 GoodData Corporation
|
|
2
|
+
|
|
3
|
+
"""GoodData AAC YAML / Declarative API code converters (WASM-powered).
|
|
4
|
+
|
|
5
|
+
Provides bidirectional conversion between AAC YAML objects (used by
|
|
6
|
+
gdc-analytics-as-code VSCode plugin) and GoodData Declarative API format.
|
|
7
|
+
|
|
8
|
+
YAML-to-Declarative functions accept parsed YAML dicts (e.g. from yaml.safe_load),
|
|
9
|
+
not raw YAML strings. Declarative-to-YAML functions accept Declarative API dicts.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from gooddata_code_convertors._wasm_runtime import ConversionError, call as _call
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"ConversionError",
|
|
16
|
+
# YAML -> Declarative
|
|
17
|
+
"yaml_dataset_to_declarative",
|
|
18
|
+
"yaml_date_dataset_to_declarative",
|
|
19
|
+
"yaml_metric_to_declarative",
|
|
20
|
+
"yaml_visualisation_to_declarative",
|
|
21
|
+
"yaml_dashboard_to_declarative",
|
|
22
|
+
"yaml_plugin_to_declarative",
|
|
23
|
+
"yaml_attribute_hierarchy_to_declarative",
|
|
24
|
+
# Declarative -> YAML
|
|
25
|
+
"declarative_dataset_to_yaml",
|
|
26
|
+
"declarative_date_instance_to_yaml",
|
|
27
|
+
"declarative_metric_to_yaml",
|
|
28
|
+
"declarative_visualisation_to_yaml",
|
|
29
|
+
"declarative_dashboard_to_yaml",
|
|
30
|
+
"declarative_plugin_to_yaml",
|
|
31
|
+
"declarative_attribute_hierarchy_to_yaml",
|
|
32
|
+
# Utilities
|
|
33
|
+
"build_afm_execution",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# YAML -> Declarative
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def yaml_dataset_to_declarative(*args) -> dict:
|
|
41
|
+
"""Convert a parsed dataset YAML dict to a declarative API dict."""
|
|
42
|
+
return _call("yamlDatasetToDeclarative", *args)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def yaml_date_dataset_to_declarative(*args) -> dict:
|
|
46
|
+
"""Convert a parsed date dataset YAML dict to a declarative API dict."""
|
|
47
|
+
return _call("yamlDateDatesetToDeclarative", *args)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def yaml_metric_to_declarative(*args) -> dict:
|
|
51
|
+
"""Convert a parsed metric YAML dict to a declarative API dict."""
|
|
52
|
+
return _call("yamlMetricToDeclarative", *args)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def yaml_visualisation_to_declarative(*args) -> dict:
|
|
56
|
+
"""Convert a parsed visualisation YAML dict to a declarative API dict."""
|
|
57
|
+
return _call("yamlVisualisationToDeclarative", *args)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def yaml_dashboard_to_declarative(*args) -> dict:
|
|
61
|
+
"""Convert a parsed dashboard YAML dict to a declarative API dict."""
|
|
62
|
+
return _call("yamlDashboardToDeclarative", *args)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def yaml_plugin_to_declarative(*args) -> dict:
|
|
66
|
+
"""Convert a parsed plugin YAML dict to a declarative API dict."""
|
|
67
|
+
return _call("yamlPluginToDeclarative", *args)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def yaml_attribute_hierarchy_to_declarative(*args) -> dict:
|
|
71
|
+
"""Convert a parsed attribute hierarchy YAML dict to a declarative API dict."""
|
|
72
|
+
return _call("yamlAttributeHierarchyToDeclarative", *args)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# Declarative -> YAML
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def declarative_dataset_to_yaml(*args) -> dict:
|
|
79
|
+
"""Convert a declarative dataset dict to YAML format."""
|
|
80
|
+
return _call("declarativeDatasetToYaml", *args)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def declarative_date_instance_to_yaml(*args) -> dict:
|
|
84
|
+
"""Convert a declarative date instance dict to YAML format."""
|
|
85
|
+
return _call("declarativeDateInstanceToYaml", *args)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def declarative_metric_to_yaml(*args) -> dict:
|
|
89
|
+
"""Convert a declarative metric dict to YAML format."""
|
|
90
|
+
return _call("declarativeMetricToYaml", *args)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def declarative_visualisation_to_yaml(*args) -> dict:
|
|
94
|
+
"""Convert a declarative visualisation dict to YAML format."""
|
|
95
|
+
return _call("declarativeVisualisationToYaml", *args)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def declarative_dashboard_to_yaml(*args) -> dict:
|
|
99
|
+
"""Convert a declarative dashboard dict to YAML format."""
|
|
100
|
+
return _call("declarativeDashboardToYaml", *args)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def declarative_plugin_to_yaml(*args) -> dict:
|
|
104
|
+
"""Convert a declarative plugin dict to YAML format."""
|
|
105
|
+
return _call("declarativePluginToYaml", *args)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def declarative_attribute_hierarchy_to_yaml(*args) -> dict:
|
|
109
|
+
"""Convert a declarative attribute hierarchy dict to YAML format."""
|
|
110
|
+
return _call("declarativeAttributeHierarchyToYaml", *args)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
# Utilities
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def build_afm_execution(*args) -> dict:
|
|
117
|
+
"""Build an AFM execution request."""
|
|
118
|
+
return _call("buildAfmExecution", *args)
|
|
Binary file
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# (C) 2026 GoodData Corporation
|
|
2
|
+
|
|
3
|
+
"""Low-level WASM runtime for code convertors via wasmtime."""
|
|
4
|
+
|
|
5
|
+
import atexit
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import tempfile
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from wasmtime import Config, Engine, Linker, Module, Store, WasiConfig
|
|
13
|
+
|
|
14
|
+
def _find_wasm_binary() -> Path:
|
|
15
|
+
"""Locate the WASM binary: packaged in wheel, or via env override for development."""
|
|
16
|
+
# 1. Packaged location (inside the wheel)
|
|
17
|
+
packaged = Path(__file__).parent / "_data" / "convertors.wasm"
|
|
18
|
+
if packaged.exists():
|
|
19
|
+
return packaged
|
|
20
|
+
# 2. Environment override for development/testing
|
|
21
|
+
env_path = os.environ.get("GOODDATA_CONVERTORS_WASM")
|
|
22
|
+
if env_path:
|
|
23
|
+
p = Path(env_path)
|
|
24
|
+
if p.exists():
|
|
25
|
+
return p
|
|
26
|
+
# 3. Not found
|
|
27
|
+
return packaged # will fail with clear error in _ensure_loaded()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
_WASM_PATH = _find_wasm_binary()
|
|
31
|
+
|
|
32
|
+
# Cache Engine and Module (expensive to create, thread-safe, immutable).
|
|
33
|
+
# A fresh Store is created per call (cheap, holds per-call state).
|
|
34
|
+
_engine: Engine | None = None
|
|
35
|
+
_module: Module | None = None
|
|
36
|
+
_linker: Linker | None = None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _ensure_loaded() -> tuple[Engine, Module, Linker]:
|
|
40
|
+
global _engine, _module, _linker
|
|
41
|
+
if _engine is None:
|
|
42
|
+
if not _WASM_PATH.exists():
|
|
43
|
+
raise FileNotFoundError(
|
|
44
|
+
f"WASM binary not found at {_WASM_PATH}. "
|
|
45
|
+
"Build it with: cd sdk/libs/sdk-code-convertors && npm run build-wasm"
|
|
46
|
+
)
|
|
47
|
+
# Build all objects before assigning globals so a partial failure
|
|
48
|
+
# doesn't leave a broken cached state.
|
|
49
|
+
engine = Engine(Config())
|
|
50
|
+
module = Module.from_file(engine, str(_WASM_PATH))
|
|
51
|
+
linker = Linker(engine)
|
|
52
|
+
linker.define_wasi()
|
|
53
|
+
_engine, _module, _linker = engine, module, linker
|
|
54
|
+
return _engine, _module, _linker
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _cleanup() -> None:
|
|
58
|
+
"""Release WASM resources before interpreter shutdown to avoid tokio runtime panic."""
|
|
59
|
+
global _engine, _module, _linker
|
|
60
|
+
_linker = None
|
|
61
|
+
_module = None
|
|
62
|
+
_engine = None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
atexit.register(_cleanup)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class ConversionError(Exception):
|
|
69
|
+
"""Raised when a WASM converter function returns an error."""
|
|
70
|
+
|
|
71
|
+
def __init__(self, message: str, stack: str | None = None):
|
|
72
|
+
self.stack = stack
|
|
73
|
+
super().__init__(message)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def call(function_name: str, *args: Any) -> Any:
|
|
77
|
+
"""Execute a converter function via the WASM JSON-RPC protocol.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
function_name: The converter function name (e.g. "yamlMetricToDeclarative").
|
|
81
|
+
*args: Arguments to pass to the converter function.
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
The result value from the converter.
|
|
85
|
+
|
|
86
|
+
Raises:
|
|
87
|
+
ConversionError: If the converter returns an error.
|
|
88
|
+
"""
|
|
89
|
+
engine, module, linker = _ensure_loaded()
|
|
90
|
+
|
|
91
|
+
payload = json.dumps({"function": function_name, "args": list(args)})
|
|
92
|
+
|
|
93
|
+
# Use delete=False so WASI can open the files by path (Windows locks
|
|
94
|
+
# NamedTemporaryFile with delete=True, blocking other handles).
|
|
95
|
+
stdin_path = stdout_path = None
|
|
96
|
+
try:
|
|
97
|
+
stdin_tmp = tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False)
|
|
98
|
+
stdin_path = stdin_tmp.name
|
|
99
|
+
stdout_tmp = tempfile.NamedTemporaryFile(mode="r", suffix=".json", delete=False)
|
|
100
|
+
stdout_path = stdout_tmp.name
|
|
101
|
+
|
|
102
|
+
stdin_tmp.write(payload)
|
|
103
|
+
stdin_tmp.close()
|
|
104
|
+
stdout_tmp.close()
|
|
105
|
+
|
|
106
|
+
store = Store(engine)
|
|
107
|
+
wasi = WasiConfig()
|
|
108
|
+
wasi.stdin_file = stdin_path
|
|
109
|
+
wasi.stdout_file = stdout_path
|
|
110
|
+
wasi.inherit_stderr()
|
|
111
|
+
store.set_wasi(wasi)
|
|
112
|
+
|
|
113
|
+
instance = linker.instantiate(store, module)
|
|
114
|
+
start = instance.exports(store)["_start"]
|
|
115
|
+
start(store)
|
|
116
|
+
|
|
117
|
+
with open(stdout_path, "r") as f:
|
|
118
|
+
output = f.read()
|
|
119
|
+
finally:
|
|
120
|
+
for path in (stdin_path, stdout_path):
|
|
121
|
+
if path:
|
|
122
|
+
try:
|
|
123
|
+
os.unlink(path)
|
|
124
|
+
except OSError:
|
|
125
|
+
pass
|
|
126
|
+
|
|
127
|
+
result = json.loads(output)
|
|
128
|
+
|
|
129
|
+
if "error" in result:
|
|
130
|
+
raise ConversionError(result["error"], result.get("stack"))
|
|
131
|
+
|
|
132
|
+
return result["result"]
|
|
File without changes
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gooddata-code-convertors
|
|
3
|
+
Version: 11.28.0a13
|
|
4
|
+
Summary: GoodData AAC YAML / Declarative API code converters (WASM-powered)
|
|
5
|
+
Project-URL: Repository, https://github.com/gooddata/gooddata-ui-sdk
|
|
6
|
+
Project-URL: Source, https://github.com/gooddata/gooddata-ui-sdk/tree/master/libs/sdk-code-convertors/python
|
|
7
|
+
License: Copyright (c) 2020-2026 GoodData Corporation
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Requires-Dist: wasmtime<31.0.0,>=25.0.0
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# gooddata-code-convertors
|
|
22
|
+
|
|
23
|
+
GoodData AAC YAML / Declarative API code converters, powered by WebAssembly.
|
|
24
|
+
|
|
25
|
+
Provides bidirectional conversion between AAC YAML format (used by the
|
|
26
|
+
[gdc-analytics-as-code](https://marketplace.visualstudio.com/items?itemName=GoodData.gooddata-code) VSCode plugin)
|
|
27
|
+
and GoodData Declarative API format.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install gooddata-code-convertors
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
YAML-to-Declarative functions accept **parsed YAML dicts** (e.g. from `yaml.safe_load`),
|
|
38
|
+
not raw YAML strings.
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
import yaml
|
|
42
|
+
from gooddata_code_convertors import yaml_metric_to_declarative, declarative_metric_to_yaml
|
|
43
|
+
|
|
44
|
+
# AAC YAML -> Declarative API
|
|
45
|
+
with open("metrics/revenue.yaml") as f:
|
|
46
|
+
parsed = yaml.safe_load(f)
|
|
47
|
+
declarative = yaml_metric_to_declarative(parsed)
|
|
48
|
+
|
|
49
|
+
# Declarative API -> AAC YAML
|
|
50
|
+
yaml_result = declarative_metric_to_yaml(declarative)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Available Converters
|
|
54
|
+
|
|
55
|
+
### YAML -> Declarative API
|
|
56
|
+
|
|
57
|
+
- `yaml_dataset_to_declarative`
|
|
58
|
+
- `yaml_date_dataset_to_declarative`
|
|
59
|
+
- `yaml_metric_to_declarative`
|
|
60
|
+
- `yaml_visualisation_to_declarative`
|
|
61
|
+
- `yaml_dashboard_to_declarative`
|
|
62
|
+
- `yaml_plugin_to_declarative`
|
|
63
|
+
- `yaml_attribute_hierarchy_to_declarative`
|
|
64
|
+
|
|
65
|
+
### Declarative API -> YAML
|
|
66
|
+
|
|
67
|
+
- `declarative_dataset_to_yaml`
|
|
68
|
+
- `declarative_date_instance_to_yaml`
|
|
69
|
+
- `declarative_metric_to_yaml`
|
|
70
|
+
- `declarative_visualisation_to_yaml`
|
|
71
|
+
- `declarative_dashboard_to_yaml`
|
|
72
|
+
- `declarative_plugin_to_yaml`
|
|
73
|
+
- `declarative_attribute_hierarchy_to_yaml`
|
|
74
|
+
|
|
75
|
+
### Utilities
|
|
76
|
+
|
|
77
|
+
- `build_afm_execution`
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
gooddata_code_convertors/__init__.py,sha256=lfjSud5sQ-swBai2UeRnYiu5X7je_DjneKiVvCms9NI,3857
|
|
2
|
+
gooddata_code_convertors/_wasm_runtime.py,sha256=fcoRUjBXxUIItWHI0RK1VWxfWUBfUbXwzdVYcqW7-7M,4105
|
|
3
|
+
gooddata_code_convertors/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
gooddata_code_convertors/_data/convertors.wasm,sha256=dQeHevj-UpXDGgzZjDlSHLmzAqUQMVJN9Ottq9gEb6M,4235321
|
|
5
|
+
gooddata_code_convertors-11.28.0a13.dist-info/METADATA,sha256=5aZ9Vg1ZAqQHVV64U4ZbkwUyuYI8W9Lt3A4fOwXUKdI,3172
|
|
6
|
+
gooddata_code_convertors-11.28.0a13.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
7
|
+
gooddata_code_convertors-11.28.0a13.dist-info/licenses/LICENSE,sha256=Oofu8mFGm_vpeVOeoIQTJOc8ageyT0ysqglWvwVMZzk,1069
|
|
8
|
+
gooddata_code_convertors-11.28.0a13.dist-info/RECORD,,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2020-2026 GoodData Corporation
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|