-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:databricks/cli into tmp/in-place-pr…
…ototype
- Loading branch information
Showing
17 changed files
with
283 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package mutator_test | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config" | ||
"github.com/databricks/cli/bundle/config/mutator" | ||
"github.com/databricks/cli/bundle/config/resources" | ||
"github.com/databricks/cli/bundle/internal/bundletest" | ||
"github.com/databricks/cli/libs/dyn" | ||
"github.com/databricks/cli/libs/vfs" | ||
"github.com/databricks/databricks-sdk-go/service/dashboards" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTranslatePathsDashboards_FilePathRelativeSubDirectory(t *testing.T) { | ||
dir := t.TempDir() | ||
touchEmptyFile(t, filepath.Join(dir, "src", "my_dashboard.lvdash.json")) | ||
|
||
b := &bundle.Bundle{ | ||
SyncRootPath: dir, | ||
SyncRoot: vfs.MustNew(dir), | ||
Config: config.Root{ | ||
Resources: config.Resources{ | ||
Dashboards: map[string]*resources.Dashboard{ | ||
"dashboard": { | ||
CreateDashboardRequest: &dashboards.CreateDashboardRequest{ | ||
DisplayName: "My Dashboard", | ||
}, | ||
FilePath: "../src/my_dashboard.lvdash.json", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
bundletest.SetLocation(b, "resources.dashboards", []dyn.Location{{ | ||
File: filepath.Join(dir, "resources/dashboard.yml"), | ||
}}) | ||
|
||
diags := bundle.Apply(context.Background(), b, mutator.TranslatePaths()) | ||
require.NoError(t, diags.Error()) | ||
|
||
// Assert that the file path for the dashboard has been converted to its local absolute path. | ||
assert.Equal( | ||
t, | ||
filepath.Join(dir, "src", "my_dashboard.lvdash.json"), | ||
b.Config.Resources.Dashboards["dashboard"].FilePath, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package root | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/databricks/databricks-sdk-go/useragent" | ||
"github.com/google/uuid" | ||
) | ||
|
||
func withCommandExecIdInUserAgent(ctx context.Context) context.Context { | ||
// A UUID that will allow us to correlate multiple API requests made by | ||
// the same CLI invocation. | ||
return useragent.InContext(ctx, "cmd-exec-id", uuid.New().String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package root | ||
|
||
import ( | ||
"context" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/databricks/databricks-sdk-go/useragent" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWithCommandExecIdInUserAgent(t *testing.T) { | ||
ctx := withCommandExecIdInUserAgent(context.Background()) | ||
|
||
// Check that the command exec ID is in the user agent string. | ||
ua := useragent.FromContext(ctx) | ||
re := regexp.MustCompile(`cmd-exec-id/([a-f0-9-]+)`) | ||
matches := re.FindAllStringSubmatch(ua, -1) | ||
|
||
// Assert that we have exactly one match and that it's a valid UUID. | ||
require.Len(t, matches, 1) | ||
_, err := uuid.Parse(matches[0][1]) | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
internal/bundle/bundles/python_wheel_task_with_cluster/databricks_template_schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"properties": { | ||
"project_name": { | ||
"type": "string", | ||
"default": "my_test_code", | ||
"description": "Unique name for this project" | ||
}, | ||
"spark_version": { | ||
"type": "string", | ||
"description": "Spark version used for job cluster" | ||
}, | ||
"node_type_id": { | ||
"type": "string", | ||
"description": "Node type id for job cluster" | ||
}, | ||
"unique_id": { | ||
"type": "string", | ||
"description": "Unique ID for job name" | ||
}, | ||
"instance_pool_id": { | ||
"type": "string", | ||
"description": "Instance pool id for job cluster" | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
internal/bundle/bundles/python_wheel_task_with_cluster/template/databricks.yml.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
bundle: | ||
name: wheel-task | ||
|
||
workspace: | ||
root_path: "~/.bundle/{{.unique_id}}" | ||
|
||
resources: | ||
clusters: | ||
test_cluster: | ||
cluster_name: "test-cluster-{{.unique_id}}" | ||
spark_version: "{{.spark_version}}" | ||
node_type_id: "{{.node_type_id}}" | ||
num_workers: 1 | ||
data_security_mode: USER_ISOLATION | ||
|
||
jobs: | ||
some_other_job: | ||
name: "[${bundle.target}] Test Wheel Job {{.unique_id}}" | ||
tasks: | ||
- task_key: TestTask | ||
existing_cluster_id: "${resources.clusters.test_cluster.cluster_id}" | ||
python_wheel_task: | ||
package_name: my_test_code | ||
entry_point: run | ||
parameters: | ||
- "one" | ||
- "two" | ||
libraries: | ||
- whl: ./dist/*.whl |
15 changes: 15 additions & 0 deletions
15
internal/bundle/bundles/python_wheel_task_with_cluster/template/setup.py.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from setuptools import setup, find_packages | ||
|
||
import {{.project_name}} | ||
|
||
setup( | ||
name="{{.project_name}}", | ||
version={{.project_name}}.__version__, | ||
author={{.project_name}}.__author__, | ||
url="https://databricks.com", | ||
author_email="[email protected]", | ||
description="my example wheel", | ||
packages=find_packages(include=["{{.project_name}}"]), | ||
entry_points={"group1": "run={{.project_name}}.__main__:main"}, | ||
install_requires=["setuptools"], | ||
) |
2 changes: 2 additions & 0 deletions
2
...rnal/bundle/bundles/python_wheel_task_with_cluster/template/{{.project_name}}/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__version__ = "0.0.1" | ||
__author__ = "Databricks" |
16 changes: 16 additions & 0 deletions
16
...rnal/bundle/bundles/python_wheel_task_with_cluster/template/{{.project_name}}/__main__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
The entry point of the Python Wheel | ||
""" | ||
|
||
import sys | ||
|
||
|
||
def main(): | ||
# This method will print the provided arguments | ||
print("Hello from my func") | ||
print("Got arguments:") | ||
print(sys.argv) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.