2023-07-25 11:35:08 +00:00
|
|
|
package libraries
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
|
|
|
)
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
func findAllTasks(b *bundle.Bundle) map[string]([]jobs.Task) {
|
2023-07-25 11:35:08 +00:00
|
|
|
r := b.Config.Resources
|
2024-04-22 11:44:34 +00:00
|
|
|
result := make(map[string]([]jobs.Task), 0)
|
2023-07-25 11:35:08 +00:00
|
|
|
for k := range b.Config.Resources.Jobs {
|
2024-04-22 11:44:34 +00:00
|
|
|
result[k] = append(result[k], r.Jobs[k].JobSettings.Tasks...)
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
2023-08-17 09:11:39 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
func FindAllEnvironments(b *bundle.Bundle) map[string]([]jobs.JobEnvironment) {
|
|
|
|
jobEnvs := make(map[string]([]jobs.JobEnvironment), 0)
|
|
|
|
for jobKey, job := range b.Config.Resources.Jobs {
|
|
|
|
if len(job.Environments) == 0 {
|
|
|
|
continue
|
2023-08-17 09:11:39 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
jobEnvs[jobKey] = job.Environments
|
2023-09-08 11:08:21 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
return jobEnvs
|
2023-09-08 11:08:21 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
func isEnvsWithLocalLibraries(envs []jobs.JobEnvironment) bool {
|
|
|
|
for _, e := range envs {
|
2024-05-21 10:00:04 +00:00
|
|
|
if e.Spec == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
for _, l := range e.Spec.Dependencies {
|
|
|
|
if IsEnvironmentDependencyLocal(l) {
|
|
|
|
return true
|
|
|
|
}
|
2023-09-08 13:45:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
func FindAllWheelTasksWithLocalLibraries(b *bundle.Bundle) []*jobs.Task {
|
|
|
|
tasks := findAllTasks(b)
|
|
|
|
envs := FindAllEnvironments(b)
|
2023-07-25 11:35:08 +00:00
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
wheelTasks := make([]*jobs.Task, 0)
|
|
|
|
for k, jobTasks := range tasks {
|
|
|
|
for i := range jobTasks {
|
|
|
|
task := &jobTasks[i]
|
|
|
|
if task.PythonWheelTask == nil {
|
|
|
|
continue
|
|
|
|
}
|
2023-07-25 11:35:08 +00:00
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
if isTaskWithLocalLibraries(*task) {
|
|
|
|
wheelTasks = append(wheelTasks, task)
|
|
|
|
}
|
2023-07-26 12:58:52 +00:00
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
if envs[k] != nil && isEnvsWithLocalLibraries(envs[k]) {
|
|
|
|
wheelTasks = append(wheelTasks, task)
|
|
|
|
}
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
return wheelTasks
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
func isTaskWithLocalLibraries(task jobs.Task) bool {
|
|
|
|
for _, l := range task.Libraries {
|
|
|
|
if IsLocalLibrary(&l) {
|
|
|
|
return true
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
return false
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
func IsTaskWithWorkspaceLibraries(task jobs.Task) bool {
|
|
|
|
for _, l := range task.Libraries {
|
|
|
|
if IsWorkspaceLibrary(&l) {
|
|
|
|
return true
|
2024-02-05 15:29:45 +00:00
|
|
|
}
|
2023-08-29 08:26:09 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 11:44:34 +00:00
|
|
|
return false
|
2023-10-09 10:10:28 +00:00
|
|
|
}
|