Skip to content

Commit 0297797

Browse files
authored
[Python] Add volumes support (#3383)
## Changes Add volume resource type support to Python ## Why It makes it possible to define volumes with Python code, similar to jobs and pipelines ## Tests Acceptance and unit tests
1 parent 09184fa commit 0297797

File tree

19 files changed

+396
-1
lines changed

19 files changed

+396
-1
lines changed

NEXT_CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Release v0.266.0
44

5+
### Notable Changes
6+
* Add support volumes in Python support ([#3383])(https://github.com/databricks/cli/pull/3383))
7+
58
### CLI
69

710
### Dependency updates
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
bundle:
2+
name: my_project
3+
4+
sync: {paths: []} # don't need to copy files
5+
6+
experimental:
7+
python:
8+
resources:
9+
- "resources:load_resources"
10+
mutators:
11+
- "mutators:update_volume"
12+
13+
resources:
14+
volumes:
15+
my_volume_1:
16+
name: "My Volume"
17+
catalog_name: "my_catalog"
18+
schema_name: "my_schema"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from dataclasses import replace
2+
3+
from databricks.bundles.core import volume_mutator
4+
from databricks.bundles.volumes import Volume
5+
6+
7+
@volume_mutator
8+
def update_volume(volume: Volume) -> Volume:
9+
assert isinstance(volume.name, str)
10+
11+
return replace(volume, name=f"{volume.name} (updated)")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Local = true
2+
Cloud = false
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]
6+
UV_ARGS = ["--with-requirements requirements-latest.txt --no-cache"]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
>>> uv run --with-requirements requirements-latest.txt --no-cache -q [CLI] bundle validate --output json
3+
{
4+
"experimental": {
5+
"python": {
6+
"mutators": [
7+
"mutators:update_volume"
8+
],
9+
"resources": [
10+
"resources:load_resources"
11+
]
12+
}
13+
},
14+
"resources": {
15+
"volumes": {
16+
"my_volume_1": {
17+
"catalog_name": "my_catalog",
18+
"name": "My Volume (updated)",
19+
"schema_name": "my_schema",
20+
"volume_type": "MANAGED"
21+
},
22+
"my_volume_2": {
23+
"catalog_name": "my_catalog_2",
24+
"name": "My Volume (2) (updated)",
25+
"schema_name": "my_schema_2",
26+
"volume_type": "MANAGED"
27+
}
28+
}
29+
}
30+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from databricks.bundles.core import Resources
2+
3+
4+
def load_resources() -> Resources:
5+
resources = Resources()
6+
7+
resources.add_volume(
8+
"my_volume_2",
9+
{
10+
"name": "My Volume (2)",
11+
"catalog_name": "my_catalog_2",
12+
"schema_name": "my_schema_2",
13+
},
14+
)
15+
16+
return resources
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
echo "$DATABRICKS_BUNDLES_WHEEL" > "requirements-latest.txt"
2+
3+
trace uv run $UV_ARGS -q $CLI bundle validate --output json | \
4+
jq "pick(.experimental.python, .resources)"
5+
6+
rm -fr .databricks __pycache__
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Local = true
2+
Cloud = false # tests don't interact with APIs
3+
4+
[EnvMatrix]
5+
UV_ARGS = [
6+
# pipelines are only supported in the latest version of the wheel
7+
"--with-requirements requirements-latest.txt --no-cache",
8+
]

experimental/python/codegen/codegen/packages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
RESOURCE_NAMESPACE = {
66
"resources.Job": "jobs",
77
"resources.Pipeline": "pipelines",
8+
"resources.Volume": "volumes",
89
}
910

1011
RESOURCE_TYPES = list(RESOURCE_NAMESPACE.keys())
@@ -17,6 +18,7 @@
1718
"jobs",
1819
"pipelines",
1920
"resources",
21+
"catalog",
2022
]
2123

2224
RENAMES = {

experimental/python/databricks/bundles/core/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
"VariableOrList",
1414
"VariableOrOptional",
1515
"job_mutator",
16-
"pipeline_mutator",
1716
"load_resources_from_current_package_module",
1817
"load_resources_from_module",
1918
"load_resources_from_modules",
2019
"load_resources_from_package_module",
20+
"pipeline_mutator",
2121
"variables",
22+
"volume_mutator",
2223
]
2324

2425
from databricks.bundles.core._bundle import Bundle
@@ -39,6 +40,7 @@
3940
ResourceMutator,
4041
job_mutator,
4142
pipeline_mutator,
43+
volume_mutator,
4244
)
4345
from databricks.bundles.core._resources import Resources
4446
from databricks.bundles.core._variable import (

0 commit comments

Comments
 (0)