Skip to content

Commit

Permalink
Filter down to Python wheel tasks only for trampoline
Browse files Browse the repository at this point in the history
Also see #635.
  • Loading branch information
pietern committed Aug 30, 2023
1 parent 12368e3 commit cc364a8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
6 changes: 6 additions & 0 deletions bundle/python/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func (t *pythonTrampoline) GetTasks(b *bundle.Bundle) []mutator.TaskWithJobKey {
tasks := r.Jobs[k].JobSettings.Tasks
for i := range tasks {
task := &tasks[i]

// Keep only Python wheel tasks
if task.PythonWheelTask == nil {
continue
}

result = append(result, mutator.TaskWithJobKey{
JobKey: k,
Task: task,
Expand Down
51 changes: 43 additions & 8 deletions bundle/python/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"strings"
"testing"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/stretchr/testify/require"
)
Expand All @@ -12,9 +15,9 @@ type testCase struct {
Actual []string
Expected string
}
type NamedParams map[string]string

type testCaseNamed struct {
Actual NamedParams
Actual map[string]string
Expected string
}

Expand All @@ -27,12 +30,12 @@ var paramsTestCases []testCase = []testCase{
}

var paramsTestCasesNamed []testCaseNamed = []testCaseNamed{
{NamedParams{}, `"python"`},
{NamedParams{"a": "1"}, `"python", "a=1"`},
{NamedParams{"a": "'1'"}, `"python", "a='1'"`},
{NamedParams{"a": `"1"`}, `"python", "a=\"1\""`},
{NamedParams{"a": "1", "b": "2"}, `"python", "a=1", "b=2"`},
{NamedParams{"data": `{"a": 1}`}, `"python", "data={\"a\": 1}"`},
{map[string]string{}, `"python"`},
{map[string]string{"a": "1"}, `"python", "a=1"`},
{map[string]string{"a": "'1'"}, `"python", "a='1'"`},
{map[string]string{"a": `"1"`}, `"python", "a=\"1\""`},
{map[string]string{"a": "1", "b": "2"}, `"python", "a=1", "b=2"`},
{map[string]string{"data": `{"a": 1}`}, `"python", "data={\"a\": 1}"`},
}

func TestGenerateParameters(t *testing.T) {
Expand Down Expand Up @@ -64,3 +67,35 @@ func TestGenerateBoth(t *testing.T) {
require.Error(t, err)
require.ErrorContains(t, err, "not allowed to pass both paramaters and named_parameters")
}

func TestTransformFiltersWheelTasksOnly(t *testing.T) {
trampoline := pythonTrampoline{}
bundle := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"job1": {
JobSettings: &jobs.JobSettings{
Tasks: []jobs.Task{
{
TaskKey: "key1",
PythonWheelTask: &jobs.PythonWheelTask{},
},
{
TaskKey: "key2",
NotebookTask: &jobs.NotebookTask{},
},
},
},
},
},
},
},
}

tasks := trampoline.GetTasks(bundle)
require.Len(t, tasks, 1)
require.Equal(t, "job1", tasks[0].JobKey)
require.Equal(t, "key1", tasks[0].Task.TaskKey)
require.NotNil(t, tasks[0].Task.PythonWheelTask)
}

0 comments on commit cc364a8

Please sign in to comment.