Skip to content

Commit 65cadfb

Browse files
authored
Respect export format for notebooks on bundle generate (#3316)
## Changes Respect export format for notebooks on `bundle generate` ## Why Notebooks in the Databricks workspace can be exported in 2 formats: Python source code (.py) or Jupyter (.ipynb). In UI, users can choose their preferred format of exporting. `bundle generate` should download in the preferred format, which we can get from a get-status call with the `return_export_info` option. ## Tests Added acceptance test <!-- If your PR needs to be included in the release notes for the next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 2dd401e commit 65cadfb

File tree

24 files changed

+341
-340
lines changed

24 files changed

+341
-340
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111

1212
### Bundles
1313
* Modified run flag validation to allow `--refresh` and `--full-refresh` flags to be used together ([#3300](https://github.com/databricks/cli/pull/3300))
14+
* Respect export format for notebooks on bundle generate ([#3316](https://github.com/databricks/cli/pull/3316))
1415

1516
### API Changes
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bundle:
2+
name: git_job
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resources:
2+
jobs:
3+
out:
4+
name: ipynb_job
5+
tasks:
6+
- task_key: test_task
7+
notebook_task:
8+
notebook_path: outnotebook.ipynb
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Local = true
2+
Cloud = false
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 0,
6+
"metadata": {
7+
"application/vnd.databricks.v1+cell": {
8+
"cellMetadata": {},
9+
"inputWidgets": {},
10+
"nuid": "[UUID]",
11+
"showTitle": false,
12+
"tableResultSettingsMap": {},
13+
"title": ""
14+
}
15+
},
16+
"outputs": [],
17+
"source": [
18+
"%python\n",
19+
"\n",
20+
"print(\"Hello, World!\")"
21+
]
22+
}
23+
],
24+
"metadata": {
25+
"application/vnd.databricks.v1+notebook": {
26+
"computePreferences": {
27+
"hardware": {
28+
"accelerator": null,
29+
"gpuPoolId": null,
30+
"memory": null
31+
}
32+
},
33+
"dashboards": [],
34+
"environmentMetadata": {
35+
"base_environment": "",
36+
"environment_version": "1"
37+
},
38+
"inputWidgetPreferences": null,
39+
"language": "python",
40+
"notebookMetadata": {
41+
"pythonIndentUnit": 2
42+
},
43+
"notebookName": "test",
44+
"widgets": {}
45+
},
46+
"language_info": {
47+
"name": "python"
48+
}
49+
},
50+
"nbformat": 4,
51+
"nbformat_minor": 0
52+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
File successfully saved to outnotebook.ipynb
2+
Job configuration successfully saved to out.job.yml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$CLI bundle generate job --existing-job-id 1234 --config-dir . --key out --force --source-dir .
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
[[Server]]
2+
Pattern = "GET /api/2.2/jobs/get"
3+
Response.Body = '''
4+
{
5+
"job_id": 11223344,
6+
"settings": {
7+
"name": "ipynb_job",
8+
"tasks": [
9+
{
10+
"task_key": "test_task",
11+
"notebook_task": {
12+
"notebook_path": "/Workspace/Users/[email protected]/outnotebook"
13+
}
14+
}
15+
]
16+
}
17+
}
18+
'''
19+
20+
[[Server]]
21+
Pattern = "GET /api/2.0/workspace/get-status"
22+
Response.Body = '''
23+
{
24+
"path": "/Workspace/Users/[email protected]/outnotebook",
25+
"object_type": "NOTEBOOK",
26+
"language": "PYTHON",
27+
"repos_export_format": "JUPYTER"
28+
}
29+
'''
30+
31+
[[Server]]
32+
Pattern = "GET /api/2.0/workspace/export"
33+
Response.Body = '''
34+
{
35+
"cells": [
36+
{
37+
"cell_type": "code",
38+
"execution_count": 0,
39+
"metadata": {
40+
"application/vnd.databricks.v1+cell": {
41+
"cellMetadata": {},
42+
"inputWidgets": {},
43+
"nuid": "7027244a-b958-4dca-aca6-57a2c638f368",
44+
"showTitle": false,
45+
"tableResultSettingsMap": {},
46+
"title": ""
47+
}
48+
},
49+
"outputs": [],
50+
"source": [
51+
"%python\n",
52+
"\n",
53+
"print(\"Hello, World!\")"
54+
]
55+
}
56+
],
57+
"metadata": {
58+
"application/vnd.databricks.v1+notebook": {
59+
"computePreferences": {
60+
"hardware": {
61+
"accelerator": null,
62+
"gpuPoolId": null,
63+
"memory": null
64+
}
65+
},
66+
"dashboards": [],
67+
"environmentMetadata": {
68+
"base_environment": "",
69+
"environment_version": "1"
70+
},
71+
"inputWidgetPreferences": null,
72+
"language": "python",
73+
"notebookMetadata": {
74+
"pythonIndentUnit": 2
75+
},
76+
"notebookName": "test",
77+
"widgets": {}
78+
},
79+
"language_info": {
80+
"name": "python"
81+
}
82+
},
83+
"nbformat": 4,
84+
"nbformat_minor": 0
85+
}
86+
'''
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bundle:
2+
name: generate-pipeline
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
resources:
2+
pipelines:
3+
out:
4+
name: generate-pipeline
5+
clusters:
6+
- custom_tags:
7+
"Tag1": "24X7-1234"
8+
- spark_conf:
9+
"spark.databricks.delta.preview.enabled": "true"
10+
libraries:
11+
- notebook:
12+
path: outnotebook.py

0 commit comments

Comments
 (0)