Skip to content

Commit e53ca69

Browse files
authored
Add Python support to default-python template (#3785)
## Changes Add Python support to `default-python` template. The option to enable PyDABs is hidden and only available through input.json. Enabling will be done together with marking "python" configs as non-experimental by adding a new template based on the `default-python` template. See non-generated code in c1159c7 ## Why This makes the PyDABs template similar to the existing `default-python`. Previously, it wasn't possible because `default-python` Python didn't use UV. ## Tests Acceptance tests for: - consistency between resources declared in YAML vs Python - formatting and snapshots for generated Python files in `resources` directory - output of "classic" configuration as end-to-end example
1 parent 3728188 commit e53ca69

File tree

34 files changed

+578
-1
lines changed

34 files changed

+578
-1
lines changed

.codegen.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"experimental/python/pyproject.toml": "version = \"$VERSION\"",
99
"experimental/python/uv.lock": "name = \"databricks-bundles\"\nversion = \"$VERSION\"",
1010
"libs/template/templates/experimental-jobs-as-code/library/versions.tmpl": "{{define \"latest_databricks_bundles_version\" -}}$VERSION{{- end}}"
11+
"libs/template/templates/default-python/library/versions.tmpl": "{{define \"latest_databricks_bundles_version\" -}}$VERSION{{- end}}"
1112
},
1213
"toolchain": {
1314
"required": [
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"project_name": "my_pydabs",
3+
"include_notebook": "$INCLUDE_NOTEBOOK",
4+
"include_dlt": "$INCLUDE_DLT",
5+
"include_python": "$INCLUDE_PYTHON",
6+
"enable_pydabs": "$enable_pydabs",
7+
"serverless": "$SERVERLESS"
8+
}

acceptance/bundle/templates/pydabs/check-consistency/out.test.toml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
== Collecting resources into ./enable_pydabs=yes
2+
3+
>>> [CLI] bundle init default-python --config-file ./input.json
4+
5+
Welcome to the default Python template for Databricks Asset Bundles!
6+
Workspace to use (auto-detected, edit in 'my_pydabs/databricks.yml'): [DATABRICKS_URL]
7+
8+
✨ Your new project has been created in the 'my_pydabs' directory!
9+
10+
Please refer to the README.md file for "getting started" instructions.
11+
See also the documentation at https://docs.databricks.com/dev-tools/bundles/index.html.
12+
13+
>>> uv venv --quiet
14+
15+
>>> uv pip install --quiet [DATABRICKS_BUNDLES_WHEEL]
16+
17+
>>> [CLI] bundle validate --output json
18+
== Collecting resources into ./enable_pydabs=no
19+
20+
>>> [CLI] bundle init default-python --config-file ./input.json
21+
22+
Welcome to the default Python template for Databricks Asset Bundles!
23+
Workspace to use (auto-detected, edit in 'my_pydabs/databricks.yml'): [DATABRICKS_URL]
24+
25+
✨ Your new project has been created in the 'my_pydabs' directory!
26+
27+
Please refer to the README.md file for "getting started" instructions.
28+
See also the documentation at https://docs.databricks.com/dev-tools/bundles/index.html.
29+
30+
>>> uv venv --quiet
31+
32+
>>> uv pip install --quiet [DATABRICKS_BUNDLES_WHEEL]
33+
34+
>>> [CLI] bundle validate --output json
35+
36+
>>> diff -Naur enable_pydabs=yes enable_pydabs=no
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
for enable_pydabs in yes no; do
2+
echo "== Collecting resources into ./enable_pydabs=$enable_pydabs"
3+
4+
enable_pydabs=$enable_pydabs envsubst < input.json.tmpl > input.json
5+
6+
trace $CLI bundle init default-python --config-file ./input.json
7+
8+
(
9+
cd my_pydabs
10+
11+
trace uv venv --quiet
12+
trace uv pip install --quiet $DATABRICKS_BUNDLES_WHEEL
13+
14+
trace $CLI bundle validate --output json | jq "pick(.resources)" > ../enable_pydabs=$enable_pydabs
15+
)
16+
17+
rm -rf my_pydabs input.json
18+
done
19+
20+
trace diff -Naur enable_pydabs=yes enable_pydabs=no
21+
rm enable_pydabs=yes enable_pydabs=no
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[EnvMatrix]
2+
INCLUDE_NOTEBOOK = ["yes", "no"]
3+
INCLUDE_DLT = ["yes", "no"]
4+
INCLUDE_PYTHON = ["yes", "no"]
5+
SERVERLESS = ["yes", "no"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"project_name": "my_pydabs",
3+
"include_notebook": "$INCLUDE_NOTEBOOK",
4+
"include_dlt": "$INCLUDE_DLT",
5+
"include_python": "$INCLUDE_PYTHON",
6+
"enable_pydabs": "yes",
7+
"serverless": "$SERVERLESS"
8+
}

acceptance/bundle/templates/pydabs/check-formatting/out.test.toml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
>>> [CLI] bundle init default-python --config-file ./input.json
3+
4+
Welcome to the default Python template for Databricks Asset Bundles!
5+
Workspace to use (auto-detected, edit in 'my_pydabs/databricks.yml'): [DATABRICKS_URL]
6+
7+
✨ Your new project has been created in the 'my_pydabs' directory!
8+
9+
Please refer to the README.md file for "getting started" instructions.
10+
See also the documentation at https://docs.databricks.com/dev-tools/bundles/index.html.
11+
12+
>>> find my_pydabs -mindepth 1 ! -name pyproject.toml ! -regex .*/resources.* -delete
13+
14+
>>> ruff format --quiet --diff --check my_pydabs
15+
16+
>>> yamlcheck.py
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
envsubst < input.json.tmpl > input.json
2+
3+
trace $CLI bundle init default-python --config-file ./input.json
4+
5+
# only keep relevant files for snapshots
6+
trace find my_pydabs -mindepth 1 ! -name 'pyproject.toml' ! -regex '.*/resources.*' -delete
7+
8+
trace ruff format --quiet --diff --check my_pydabs
9+
trace yamlcheck.py
10+
11+
rm -rf my_pydabs input.json

0 commit comments

Comments
 (0)