Skip to content

Commit 59ebbcb

Browse files
authored
Fix default-python template not to add environments when serverless=yes and include_python=no (#2866)
## Changes Do not add environments section in default-python templates if there is no python_wheel_task section. ## Why Since it's python_wheel_task that triggers implicit artifact and wheel creation, environment fails with the error when resolving `./dist/*.whl` pattern. ## Tests New acceptance test that extensively deploys all possible combinations of default-python template. On main branch this test fails for combinations with serverless=yes include_python=no.
1 parent 45b327d commit 59ebbcb

File tree

7 files changed

+124
-2
lines changed

7 files changed

+124
-2
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
* Removed unused fields from resources.models schema: creation\_timestamp, last\_updated\_timestamp, latest\_versions and user\_id. Using them now raises a warning.
1313
* Preserve folder structure for app source code in bundle generate ([#2848](https://github.com/databricks/cli/pull/2848))
1414
* Fixed normalising requirements file path in dependencies section ([#2861](https://github.com/databricks/cli/pull/2861))
15+
* Fix default-python template not to add environments when serverless=yes and include\_python=no ([#2866](https://github.com/databricks/cli/pull/2866))
1516

1617
### API Changes
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import os
4+
import subprocess
5+
6+
7+
BUILDING = "Building python_artifact"
8+
UPLOADING = "Uploading dist/"
9+
STATE = "Updating deployment state"
10+
11+
12+
def is_printable_line(line):
13+
# only shown when include_python=yes
14+
if line.startswith(BUILDING):
15+
return False
16+
17+
# only shown when include_python=yes
18+
if line.startswith(UPLOADING):
19+
return False
20+
21+
# not shown when all settings are equal to "no"
22+
if line.startswith(STATE):
23+
return False
24+
25+
return True
26+
27+
28+
p = subprocess.run(sys.argv[1:], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8")
29+
try:
30+
assert p.returncode == 0
31+
assert p.stdout == ""
32+
for line in p.stderr.strip().split("\n"):
33+
if is_printable_line(line):
34+
print(line.strip())
35+
36+
if os.environ["INCLUDE_PYTHON"] == "yes":
37+
assert BUILDING in p.stderr
38+
assert UPLOADING in p.stderr
39+
else:
40+
assert BUILDING not in p.stderr
41+
assert UPLOADING not in p.stderr
42+
43+
except:
44+
print(f"STDOUT: {len(p.stdout)} chars")
45+
if p.stdout:
46+
print(p.stdout)
47+
print(f"STDERR: {len(p.stderr)} chars")
48+
if p.stderr:
49+
print(p.stderr)
50+
print(f"CODE: {p.returncode}", flush=True)
51+
raise
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"project_name": "my_default_python",
3+
"include_notebook": "$INCLUDE_NOTEBOOK",
4+
"include_dlt": "$INCLUDE_DLT",
5+
"include_python": "$INCLUDE_PYTHON",
6+
"serverless": "$SERVERLESS"
7+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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_default_python/databricks.yml'): [DATABRICKS_URL]
6+
7+
✨ Your new project has been created in the 'my_default_python' 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+
>>> [CLI] bundle validate -t dev
13+
Name: my_default_python
14+
Target: dev
15+
Workspace:
16+
Host: [DATABRICKS_URL]
17+
User: [USERNAME]
18+
Path: /Workspace/Users/[USERNAME]/.bundle/my_default_python/dev
19+
20+
Validation OK!
21+
22+
>>> [CLI] bundle validate -t prod
23+
Name: my_default_python
24+
Target: prod
25+
Workspace:
26+
Host: [DATABRICKS_URL]
27+
User: [USERNAME]
28+
Path: /Workspace/Users/[USERNAME]/.bundle/my_default_python/prod
29+
30+
Validation OK!
31+
32+
>>> ../check_output.py [CLI] bundle deploy -t dev
33+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files...
34+
Deploying resources...
35+
Deployment complete!
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
envsubst < input.json.tmpl > input.json
2+
trace $CLI bundle init default-python --config-file ./input.json
3+
4+
cd ./my_default_python
5+
trace $CLI bundle validate -t dev
6+
trace $CLI bundle validate -t prod
7+
8+
trace ../check_output.py $CLI bundle deploy -t dev
9+
10+
# Fails on testserver with: Error: Method Not Allowed
11+
#trace ../check_output.py $CLI bundle deploy -t prod
12+
13+
# Do not affect this repository's git behaviour #2318
14+
mv .gitignore out.gitignore
15+
rm .databricks/.gitignore
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Ignore = ["my_default_python", "input.json"]
2+
EnvMatrix.INCLUDE_NOTEBOOK = ["yes", "no"]
3+
EnvRepl.INCLUDE_NOTEBOOK = false
4+
EnvMatrix.INCLUDE_DLT = ["yes", "no"]
5+
EnvRepl.INCLUDE_DLT = false
6+
EnvMatrix.INCLUDE_PYTHON = ["yes", "no"]
7+
EnvRepl.INCLUDE_PYTHON = false
8+
EnvMatrix.SERVERLESS = ["yes", "no"]
9+
EnvRepl.SERVERLESS = false
10+
11+
[[Repls]]
12+
Old = '202\d{5}.\d{5,}'
13+
New = '[VERSION_TIMESTAMP]'

libs/template/templates/default-python/template/{{.project_name}}/resources/{{.project_name}}.job.yml.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ resources:
6666
{{- end -}}
6767
{{else}}
6868
{{- end}}
69-
{{if $with_serverless}}
69+
{{if $with_serverless}}{{if (eq .include_python "yes")}}
7070
# A list of task execution environment specifications that can be referenced by tasks of this job.
7171
environments:
7272
- environment_key: default
@@ -77,7 +77,7 @@ resources:
7777
client: "1"
7878
dependencies:
7979
- ../dist/*.whl
80-
{{ else }}
80+
{{end}}{{ else }}
8181
job_clusters:
8282
- job_cluster_key: job_cluster
8383
new_cluster:

0 commit comments

Comments
 (0)