Fixed processing jobs libraries with remote path (#638)

## Changes
Some library paths such as for Spark jobs, can reference a lib on remote
path, for example DBFS.
This PR fixes how CLI handles such libraries and do not report them as
missing locally.

## Tests
Added unit tests + ran `databricks bundle deploy` manually
This commit is contained in:
Andrew Nester 2023-08-07 11:55:30 +02:00 committed by GitHub
parent ce9c9148c9
commit f7a76ff5d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"path/filepath"
"strings"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
@ -111,5 +112,20 @@ func libPath(library *compute.Library) string {
}
func isLocalLibrary(library *compute.Library) bool {
return libPath(library) != ""
path := libPath(library)
if path == "" {
return false
}
return !isDbfsPath(path) && !isWorkspacePath(path)
}
func isDbfsPath(path string) bool {
return strings.HasPrefix(path, "dbfs:/")
}
func isWorkspacePath(path string) bool {
return strings.HasPrefix(path, "/Workspace/") ||
strings.HasPrefix(path, "/Users/") ||
strings.HasPrefix(path, "/Shared/")
}

View File

@ -17,3 +17,5 @@ resources:
python_wheel_task:
package_name: "my_test_code"
entry_point: "run"
libraries:
- whl: ./my_test_code/dist/*.whl

View File

@ -0,0 +1,15 @@
bundle:
name: python-wheel
resources:
jobs:
test_job:
name: "[${bundle.environment}] My Wheel Job"
tasks:
- task_key: TestTask
existing_cluster_id: "0717-132531-5opeqon1"
python_wheel_task:
package_name: "my_test_code"
entry_point: "run"
libraries:
- whl: dbfs://path/to/dist/mywheel.whl

View File

@ -11,3 +11,5 @@ resources:
python_wheel_task:
package_name: "my_test_code"
entry_point: "run"
libraries:
- whl: ./dist/*.whl

View File

@ -6,6 +6,7 @@ import (
"testing"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/libraries"
"github.com/databricks/cli/bundle/phases"
"github.com/stretchr/testify/require"
)
@ -21,6 +22,10 @@ func TestBundlePythonWheelBuild(t *testing.T) {
matches, err := filepath.Glob("python_wheel/my_test_code/dist/my_test_code-*.whl")
require.NoError(t, err)
require.Equal(t, 1, len(matches))
match := libraries.MatchWithArtifacts()
err = match.Apply(context.Background(), b)
require.NoError(t, err)
}
func TestBundlePythonWheelBuildAutoDetect(t *testing.T) {
@ -34,4 +39,21 @@ func TestBundlePythonWheelBuildAutoDetect(t *testing.T) {
matches, err := filepath.Glob("python_wheel/my_test_code/dist/my_test_code-*.whl")
require.NoError(t, err)
require.Equal(t, 1, len(matches))
match := libraries.MatchWithArtifacts()
err = match.Apply(context.Background(), b)
require.NoError(t, err)
}
func TestBundlePythonWheelWithDBFSLib(t *testing.T) {
b, err := bundle.Load("./python_wheel_dbfs_lib")
require.NoError(t, err)
m := phases.Build()
err = m.Apply(context.Background(), b)
require.NoError(t, err)
match := libraries.MatchWithArtifacts()
err = match.Apply(context.Background(), b)
require.NoError(t, err)
}