Process only Python wheel tasks which have local libraries used (#751)

## Changes
Process only Python wheel tasks which have local libraries used

## Tests
Updated uni test to catch the regression
This commit is contained in:
Andrew Nester 2023-09-08 13:08:21 +02:00 committed by GitHub
parent f7566b8264
commit 67af171a68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 7 deletions

View File

@ -27,9 +27,9 @@ func (m *detectPkg) Name() string {
}
func (m *detectPkg) Apply(ctx context.Context, b *bundle.Bundle) error {
wheelTasks := libraries.FindAllWheelTasks(b)
wheelTasks := libraries.FindAllWheelTasksWithLocalLibraries(b)
if len(wheelTasks) == 0 {
log.Infof(ctx, "No wheel tasks in databricks.yml config, skipping auto detect")
log.Infof(ctx, "No local wheel tasks in databricks.yml config, skipping auto detect")
return nil
}
cmdio.LogString(ctx, "artifacts.whl.AutoDetect: Detecting Python wheel project...")

View File

@ -26,7 +26,7 @@ func (*fromLibraries) Apply(ctx context.Context, b *bundle.Bundle) error {
return nil
}
tasks := libraries.FindAllWheelTasks(b)
tasks := libraries.FindAllWheelTasksWithLocalLibraries(b)
for _, task := range tasks {
for _, lib := range task.Libraries {
matches, err := filepath.Glob(filepath.Join(b.Config.Path, lib.Whl))

View File

@ -56,11 +56,11 @@ func findAllTasks(b *bundle.Bundle) []*jobs.Task {
return result
}
func FindAllWheelTasks(b *bundle.Bundle) []*jobs.Task {
func FindAllWheelTasksWithLocalLibraries(b *bundle.Bundle) []*jobs.Task {
tasks := findAllTasks(b)
wheelTasks := make([]*jobs.Task, 0)
for _, task := range tasks {
if task.PythonWheelTask != nil {
if task.PythonWheelTask != nil && IsTaskWithLocalLibraries(task) {
wheelTasks = append(wheelTasks, task)
}
}
@ -68,6 +68,16 @@ func FindAllWheelTasks(b *bundle.Bundle) []*jobs.Task {
return wheelTasks
}
func IsTaskWithLocalLibraries(task *jobs.Task) bool {
for _, l := range task.Libraries {
if isLocalLibrary(&l) {
return true
}
}
return false
}
func isMissingRequiredLibraries(task *jobs.Task) bool {
if task.Libraries != nil {
return false

View File

@ -7,6 +7,7 @@ import (
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config/mutator"
"github.com/databricks/cli/bundle/libraries"
"github.com/databricks/databricks-sdk-go/service/jobs"
)
@ -72,8 +73,8 @@ func (t *pythonTrampoline) GetTasks(b *bundle.Bundle) []mutator.TaskWithJobKey {
for i := range tasks {
task := &tasks[i]
// Keep only Python wheel tasks
if task.PythonWheelTask == nil {
// Keep only Python wheel tasks with local libraries referenced
if task.PythonWheelTask == nil || !libraries.IsTaskWithLocalLibraries(task) {
continue
}

View File

@ -9,6 +9,7 @@ import (
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/paths"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/databricks-sdk-go/service/compute"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/stretchr/testify/require"
)
@ -82,11 +83,21 @@ func TestTransformFiltersWheelTasksOnly(t *testing.T) {
{
TaskKey: "key1",
PythonWheelTask: &jobs.PythonWheelTask{},
Libraries: []compute.Library{
{Whl: "./dist/test.whl"},
},
},
{
TaskKey: "key2",
NotebookTask: &jobs.NotebookTask{},
},
{
TaskKey: "key3",
PythonWheelTask: &jobs.PythonWheelTask{},
Libraries: []compute.Library{
{Whl: "dbfs:/FileStore/dist/test.whl"},
},
},
},
},
},