diff --git a/knowledge_base/artifacts_dynamic_version_uv/.gitignore b/knowledge_base/artifacts_dynamic_version_uv/.gitignore new file mode 100644 index 0000000..e32bcdd --- /dev/null +++ b/knowledge_base/artifacts_dynamic_version_uv/.gitignore @@ -0,0 +1,2 @@ +.databricks +dist/ diff --git a/knowledge_base/artifacts_dynamic_version_uv/README.md b/knowledge_base/artifacts_dynamic_version_uv/README.md new file mode 100644 index 0000000..7536d21 --- /dev/null +++ b/knowledge_base/artifacts_dynamic_version_uv/README.md @@ -0,0 +1,43 @@ +# Wheel with dynamic version and uv + +This Declarative Automation Bundles example builds a Python wheel with `uv build` and runs it in a serverless job. +The `presets.artifacts_dynamic_version` setting adds a build timestamp to the wheel version on each deploy. +Each deploy installs the new wheel. +The base version in `pyproject.toml` stays `0.1.0`. + +For more information, see the [artifacts documentation](https://docs.databricks.com/aws/en/dev-tools/bundles/settings#artifacts). + +## Prerequisites + +* Databricks CLI v1.20.0 or above +* uv 0.10 or above (see [Installing uv](https://docs.astral.sh/uv/getting-started/installation/)) +* A workspace with serverless compute for jobs + +## Usage + +1. Deploy the bundle. The CLI builds the wheel with `uv build --wheel`: + ```bash + databricks bundle deploy + ``` +2. Run the job: + ```bash + databricks bundle run dynamic_version_job + ``` + The output shows the patched version and the marker: + ``` + dynamic_version_demo 0.1.0+: marker-v1 + ``` +3. Change `MARKER` in `src/dynamic_version_demo/main.py` to `marker-v2`. Keep `version = "0.1.0"` in `pyproject.toml`. +4. Deploy and run the job again: + ```bash + databricks bundle deploy + databricks bundle run dynamic_version_job + ``` + The output shows a new version suffix and the new marker: + ``` + dynamic_version_demo 0.1.0+: marker-v2 + ``` +5. Remove the deployed resources: + ```bash + databricks bundle destroy + ``` diff --git a/knowledge_base/artifacts_dynamic_version_uv/databricks.yml b/knowledge_base/artifacts_dynamic_version_uv/databricks.yml new file mode 100644 index 0000000..f8b0710 --- /dev/null +++ b/knowledge_base/artifacts_dynamic_version_uv/databricks.yml @@ -0,0 +1,30 @@ +bundle: + name: artifacts_dynamic_version_uv + databricks_cli_version: ">= 1.20.0" + +include: + - resources/*.yml + +artifacts: + default: + type: whl + build: uv build --wheel + path: . + +# Append a build timestamp to the wheel version on each deploy. +# Clusters and serverless environments then install the new wheel without a version bump. +# To enable this for one artifact only, set `dynamic_version: true` on that artifact. +presets: + artifacts_dynamic_version: true + +targets: + dev: + default: true + mode: development + workspace: + root_path: /Workspace/bundle-examples/${bundle.name}/${bundle.target}/${workspace.current_user.short_name} + + prod: + mode: production + workspace: + root_path: /Workspace/bundle-examples/${bundle.name}/${bundle.target} diff --git a/knowledge_base/artifacts_dynamic_version_uv/pyproject.toml b/knowledge_base/artifacts_dynamic_version_uv/pyproject.toml new file mode 100644 index 0000000..d47f78c --- /dev/null +++ b/knowledge_base/artifacts_dynamic_version_uv/pyproject.toml @@ -0,0 +1,13 @@ +[project] +name = "dynamic_version_demo" +# Keep this version fixed. The bundle adds a build timestamp on each deploy. +version = "0.1.0" +requires-python = ">=3.10" +dependencies = [] + +[project.scripts] +main = "dynamic_version_demo.main:main" + +[build-system] +requires = ["uv_build>=0.10.0,<0.11"] +build-backend = "uv_build" diff --git a/knowledge_base/artifacts_dynamic_version_uv/resources/dynamic_version_job.job.yml b/knowledge_base/artifacts_dynamic_version_uv/resources/dynamic_version_job.job.yml new file mode 100644 index 0000000..a1b83af --- /dev/null +++ b/knowledge_base/artifacts_dynamic_version_uv/resources/dynamic_version_job.job.yml @@ -0,0 +1,17 @@ +resources: + jobs: + dynamic_version_job: + name: dynamic_version_job + tasks: + - task_key: main + environment_key: default + python_wheel_task: + package_name: dynamic_version_demo + entry_point: main + + environments: + - environment_key: default + spec: + environment_version: "6" + dependencies: + - ../dist/*.whl diff --git a/knowledge_base/artifacts_dynamic_version_uv/src/dynamic_version_demo/__init__.py b/knowledge_base/artifacts_dynamic_version_uv/src/dynamic_version_demo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/knowledge_base/artifacts_dynamic_version_uv/src/dynamic_version_demo/main.py b/knowledge_base/artifacts_dynamic_version_uv/src/dynamic_version_demo/main.py new file mode 100644 index 0000000..6c80f10 --- /dev/null +++ b/knowledge_base/artifacts_dynamic_version_uv/src/dynamic_version_demo/main.py @@ -0,0 +1,12 @@ +from importlib.metadata import version + +# Change this value and deploy again. You do not need to bump the version. +MARKER = "marker-v1" + + +def main(): + print(f"dynamic_version_demo {version('dynamic_version_demo')}: {MARKER}") + + +if __name__ == "__main__": + main() diff --git a/knowledge_base/artifacts_dynamic_version_uv/uv.lock b/knowledge_base/artifacts_dynamic_version_uv/uv.lock new file mode 100644 index 0000000..16a8001 --- /dev/null +++ b/knowledge_base/artifacts_dynamic_version_uv/uv.lock @@ -0,0 +1,8 @@ +version = 1 +revision = 3 +requires-python = ">=3.10" + +[[package]] +name = "dynamic-version-demo" +version = "0.1.0" +source = { editable = "." }