Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"pages": []
}
17 changes: 17 additions & 0 deletions acceptance/bundle/python/dashboards-support/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
bundle:
name: my_project

sync: {paths: []} # don't need to copy files

python:
resources:
- "resources:load_resources"
mutators:
- "mutators:update_dashboard"

resources:
dashboards:
my_dashboard_1:
display_name: "My Dashboard"
file_path: dashboard.lvdash.json
warehouse_id: my_warehouse
11 changes: 11 additions & 0 deletions acceptance/bundle/python/dashboards-support/mutators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from dataclasses import replace

from databricks.bundles.core import dashboard_mutator
from databricks.bundles.dashboards import Dashboard


@dashboard_mutator
def update_dashboard(dashboard: Dashboard) -> Dashboard:
assert isinstance(dashboard.display_name, str)

return replace(dashboard, display_name=f"{dashboard.display_name} (updated)")
4 changes: 4 additions & 0 deletions acceptance/bundle/python/dashboards-support/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions acceptance/bundle/python/dashboards-support/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

>>> uv run [UV_ARGS] -q [CLI] bundle validate --output json
{
"experimental": {
"python": {
"mutators": [
"mutators:update_dashboard"
],
"resources": [
"resources:load_resources"
]
}
},
"resources": {
"dashboards": {
"my_dashboard_1": {
"display_name": "My Dashboard (updated)",
"embed_credentials": false,
"file_path": "dashboard.lvdash.json",
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/my_project/default/resources",
"serialized_dashboard": "{\n \"pages\": []\n}\n",
"warehouse_id": "my_warehouse"
},
"my_dashboard_2": {
"display_name": "My Dashboard (2) (updated)",
"embed_credentials": false,
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/my_project/default/resources",
"serialized_dashboard": {
"pages": [
{
"name": "python_page"
}
]
},
"warehouse_id": "my_warehouse_2"
}
}
}
}
16 changes: 16 additions & 0 deletions acceptance/bundle/python/dashboards-support/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from databricks.bundles.core import Resources


def load_resources() -> Resources:
resources = Resources()

resources.add_dashboard(
"my_dashboard_2",
{
"display_name": "My Dashboard (2)",
"serialized_dashboard": {"pages": [{"name": "python_page"}]},
"warehouse_id": "my_warehouse_2",
},
)

return resources
5 changes: 5 additions & 0 deletions acceptance/bundle/python/dashboards-support/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

trace uv run $UV_ARGS -q $CLI bundle validate --output json | \
jq "pick(.experimental.python, .resources)"

rm -fr .databricks __pycache__
4 changes: 4 additions & 0 deletions acceptance/bundle/python/dashboards-support/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Cloud = false # tests don't interact with APIs

# dashboards are only supported in the current version of the wheel
EnvMatrix.PYDAB_VERSION = ["current"]
2 changes: 1 addition & 1 deletion python/codegen/codegen/generated_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_code(
b = CodeBuilder()

b.append(
"from typing import Literal, Optional, TypedDict, ClassVar, TYPE_CHECKING\n"
"from typing import Any, Literal, Optional, TypedDict, ClassVar, TYPE_CHECKING\n"
)
b.append("from enum import Enum\n")
b.append("from dataclasses import dataclass, replace, field\n")
Expand Down
3 changes: 3 additions & 0 deletions python/codegen/codegen/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"resources.Schema": "schemas",
"resources.Volume": "volumes",
"resources.Alert": "alerts",
"resources.Dashboard": "dashboards",
}

RESOURCE_TYPES = list(RESOURCE_NAMESPACE.keys())
Expand All @@ -20,6 +21,7 @@
"number": "float",
"int64": "int",
"float64": "float",
"interface": "Any",
}

PRIMITIVES = [
Expand All @@ -31,6 +33,7 @@
"int",
"int64",
"float64",
"interface",
]


Expand Down
14 changes: 14 additions & 0 deletions python/codegen/codegen_tests/test_generated_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ def test_generate_type_string():
)


def test_generate_type_interface():
generated_type = generate_type(
namespace="dashboards",
ref="#/$defs/interface",
is_param=False,
)

assert generated_type == GeneratedType(
name="Any",
package=None,
parameters=[],
)


def test_generate_type_dict():
generated_type = generate_type(
namespace="jobs",
Expand Down
2 changes: 2 additions & 0 deletions python/databricks/bundles/core/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions python/databricks/bundles/core/_generated/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 118 additions & 0 deletions python/databricks/bundles/core/_generated/dashboards.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions python/databricks/bundles/core/_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def _transform_field(cls: Type[_T], field: Field, value: Any) -> _T:
def _transform(cls: Type[_T], value: Any) -> _T:
origin = get_origin(cls)

if cls is Any:
return value

if is_dataclass(cls) and isinstance(value, cls): # type:ignore
return value

Expand Down
42 changes: 42 additions & 0 deletions python/databricks/bundles/dashboards/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading