Skip to content
Closed
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
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
### Dependency updates

### Bundles
* Update default-python template to make DB Connect work out of the box for unit tests, using uv to install dependencies ([#3254](https://github.com/databricks/cli/pull/3254))

### API Changes
2 changes: 1 addition & 1 deletion acceptance/bundle/help/bundle-init/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Initialize using a bundle template to get started quickly.

TEMPLATE_PATH optionally specifies which template to use. It can be one of the following:
- default-python: The default Python template for Notebooks and Lakeflow
- default-python: The default Python template, using Python files or notebooks with Lakeflow
- default-sql: The default SQL template for .sql files that run with Databricks SQL
- dbt-sql: The dbt SQL template (databricks.com/blog/delivering-cost-effective-data-real-time-dbt-and-databricks)
- mlops-stacks: The Databricks MLOps Stacks template (github.com/databricks/mlops-stacks)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

>>> [CLI] bundle init .
✨ Successfully initialized template
Error: failed to compute file content for hello.txt.tmpl. error in {{ .s | lower }}
{{ .s | upper }}
: template: :1: function "lower" not defined

>>> cat hello.txt
abcd0123😀
ABCD0123😀
Exit code: 1

This file was deleted.

22 changes: 10 additions & 12 deletions acceptance/bundle/templates/default-python/classic/output.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@

>>> [CLI] bundle init default-python --config-file ./input.json --output-dir output

Welcome to the default Python template for Databricks Asset Bundles!
Workspace to use (auto-detected, edit in 'my_default_python/databricks.yml'): [DATABRICKS_URL]

Please answer the below to tailor your project to your preferences.
You can always change your mind and change your configuration in the databricks.yml file later.

Note that [DATABRICKS_URL] is used for initialization
(see https://docs.databricks.com/dev-tools/cli/profiles.html for how to change your profile).

✨ Your new project has been created in the 'my_default_python' directory!

Please refer to the README.md file for "getting started" instructions.
See also the documentation at https://docs.databricks.com/dev-tools/bundles/index.html.

>>> [CLI] bundle validate -t dev
Error: path [TEST_TMP_DIR]/output/dist/*.whl is not contained in sync root path

Name: my_default_python
Target: dev
Workspace:
Host: [DATABRICKS_URL]
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/my_default_python/dev

Validation OK!

>>> [CLI] bundle validate -t prod
Name: my_default_python
Target: prod
Workspace:
Host: [DATABRICKS_URL]
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/my_default_python/prod
Found 1 error

Validation OK!
Exit code: 1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"recommendations": [
"databricks.databricks",
"ms-python.vscode-pylance",
"redhat.vscode-yaml"
]
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
{
"python.analysis.stubPath": ".vscode",
"jupyter.interactiveWindow.cellMarker.codeRegex": "^# COMMAND ----------|^# Databricks notebook source|^(#\\s*%%|#\\s*\\<codecell\\>|#\\s*In\\[\\d*?\\]|#\\s*In\\[ \\])",
"jupyter.interactiveWindow.cellMarker.default": "# COMMAND ----------",
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.analysis.extraPaths": ["src"],
"files.exclude": {
"**/*.egg-info": true,
"**/__pycache__": true,
".pytest_cache": true,
"dist": true,
},
"files.associations": {
"**/.gitkeep": "markdown"
}

// Pylance settings (VS Code)
// Set typeCheckingMode to "basic" to enable type checking!
"python.analysis.typeCheckingMode": "off",
"python.analysis.extraPaths": ["src", "lib", "resources"],
"python.analysis.diagnosticMode": "workspace",
"python.analysis.stubPath": ".vscode",

// Pyright settings (Cursor)
// Set typeCheckingMode to "basic" to enable type checking!
"cursorpyright.analysis.typeCheckingMode": "off",
"cursorpyright.analysis.extraPaths": ["src", "lib", "resources"],
"cursorpyright.analysis.diagnosticMode": "workspace",
"cursorpyright.analysis.stubPath": ".vscode",

// General Python settings
"python.defaultInterpreterPath": "./.venv/bin/python",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"[python]": {
"editor.defaultFormatter": "ms-python.python",
"editor.formatOnSave": true,
},
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
# my_default_python

The 'my_default_python' project was generated by using the default-python template.
For documentation on the Databricks Asset Bundles format use for this project,
and for CI/CD configuration, see https://docs.databricks.com/aws/en/dev-tools/bundles.

* `src/`: Python source code for this project.
* `src/shared`: Shared source code across all jobs/pipelines/etc.
* `src/default_python_etl`: Python source code for the default_python_etl pipeline.
* `resources/`: Resource configurations (jobs, pipelines, etc.)
* `tests/`: Unit tests.
* `fixtures/`: Fixtures for data sets (primarily used for testing).

## Getting started

0. Install UV: https://docs.astral.sh/uv/getting-started/installation/
Choose how you want to work on this project:

(a) Directly in your Databricks workspace, see
https://docs.databricks.com/dev-tools/bundles/workspace.

(b) Locally with an IDE like Cursor or VS Code, see
https://docs.databricks.com/vscode-ext.

(c) With command line tools, see https://docs.databricks.com/dev-tools/cli/databricks-cli.html

Dependencies for this project should be installed using uv:

* Make sure you have the UV package manager installed.
It's an alternative to tools like pip: https://docs.astral.sh/uv/getting-started/installation/.
* Run `uv sync --dev` to install the project's dependencies.

1. Install the Databricks CLI from https://docs.databricks.com/dev-tools/cli/databricks-cli.html

2. Authenticate to your Databricks workspace, if you have not done so already:
# Using this project using the CLI

The Databricks workspace and IDE extensions provide a graphical interface for working
with this project. It's also possible to interact with it directly using the CLI:

1. Authenticate to your Databricks workspace, if you have not done so already:
```
$ databricks configure
```

3. To deploy a development copy of this project, type:
2. To deploy a development copy of this project, type:
```
$ databricks bundle deploy --target dev
```
Expand All @@ -23,9 +50,9 @@ The 'my_default_python' project was generated by using the default-python templa
This deploys everything that's defined for this project.
For example, the default template would deploy a job called
`[dev yourname] my_default_python_job` to your workspace.
You can find that job by opening your workpace and clicking on **Workflows**.
You can find that job by opening your workpace and clicking on **Jobs & Pipelines**.

4. Similarly, to deploy a production copy, type:
3. Similarly, to deploy a production copy, type:
```
$ databricks bundle deploy --target prod
```
Expand All @@ -35,17 +62,12 @@ The 'my_default_python' project was generated by using the default-python templa
is paused when deploying in development mode (see
https://docs.databricks.com/dev-tools/bundles/deployment-modes.html).

5. To run a job or pipeline, use the "run" command:
4. To run a job or pipeline, use the "run" command:
```
$ databricks bundle run
```
6. Optionally, install the Databricks extension for Visual Studio code for local development from
https://docs.databricks.com/dev-tools/vscode-ext.html. It can configure your
virtual environment and setup Databricks Connect for running unit tests locally.
When not using these tools, consult your development environment's documentation
and/or the documentation for Databricks Connect for manually setting up your environment
(https://docs.databricks.com/en/dev-tools/databricks-connect/python/index.html).

7. For documentation on the Databricks asset bundles format used
for this project, and for CI/CD configuration, see
https://docs.databricks.com/dev-tools/bundles/index.html.
5. Finally, to run tests locally, use `pytest`:
```
$ uv run pytest
```

Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ bundle:
name: my_default_python
uuid: [UUID]

include:
- resources/*.yml
- resources/*/*.yml

artifacts:
python_artifact:
type: whl
build: uv build --wheel

include:
- resources/*.yml
- resources/*/*.yml
# Variable declarations. These variables are assigned in the dev/prod targets below.
variables:
catalog:
description: The catalog to use
schema:
description: The schema to use

targets:
dev:
Expand All @@ -23,20 +30,20 @@ targets:
default: true
workspace:
host: [DATABRICKS_URL]

variables:
catalog: hive_metastore
schema: ${workspace.current_user.short_name}
presets:
# Set dynamic_version: true on all artifacts of type "whl".
# This makes "bundle deploy" add a timestamp to wheel's version before uploading,
# new wheel takes over the previous installation even if actual wheel version is unchanged.
# See https://docs.databricks.com/aws/en/dev-tools/bundles/settings
artifacts_dynamic_version: true

prod:
mode: production
workspace:
host: [DATABRICKS_URL]
# We explicitly deploy to /Workspace/Users/[USERNAME] to make sure we only have a single copy.
root_path: /Workspace/Users/[USERNAME]/.bundle/${bundle.name}/${bundle.target}
variables:
catalog: hive_metastore
schema: prod
permissions:
- user_name: [USERNAME]
level: CAN_MANAGE
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
# Fixtures
# Test fixtures directory

This folder is reserved for fixtures, such as CSV files.

Below is an example of how to load fixtures as a data frame:
Add JSON or CSV files here. In tests, use them with `load_fixture()`:

```
import pandas as pd
import os

def get_absolute_path(*relative_parts):
if 'dbutils' in globals():
base_dir = os.path.dirname(dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get()) # type: ignore
path = os.path.normpath(os.path.join(base_dir, *relative_parts))
return path if path.startswith("/Workspace") else "/Workspace" + path
else:
return os.path.join(*relative_parts)

csv_file = get_absolute_path("..", "fixtures", "mycsv.csv")
df = pd.read_csv(csv_file)
display(df)
def test_using_fixture(load_fixture):
data = load_fixture("my_data.json")
assert len(data) >= 1
```
Loading
Loading