-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make a notebook wrapper for Python wheel tasks optional (#797)
## Changes Instead of always using notebook wrapper for Python wheel tasks, let's make this an opt-in option. Now by default Python wheel tasks will be deployed as is to Databricks platform. If notebook wrapper required (DBR < 13.1 or other configuration differences), users can provide a following experimental setting ``` experimental: python_wheel_wrapper: true ``` Fixes #783, databricks/databricks-asset-bundles-dais2023#8 ## Tests Added unit tests. Integration tests passed for both cases ``` helpers.go:163: [databricks stdout]: Hello from my func helpers.go:163: [databricks stdout]: Got arguments: helpers.go:163: [databricks stdout]: ['my_test_code', 'one', 'two'] ... Bundle remote directory is ***/.bundle/ac05d5e8-ed4b-4e34-b3f2-afa73f62b021 Deleted snapshot file at /var/folders/nt/xjv68qzs45319w4k36dhpylc0000gp/T/TestAccPythonWheelTaskDeployAndRunWithWrapper3733431114/001/.databricks/bundle/default/sync-snapshots/cac1e02f3941a97b.json Successfully deleted files! --- PASS: TestAccPythonWheelTaskDeployAndRunWithWrapper (214.18s) PASS coverage: 93.5% of statements in ./... ok github.com/databricks/cli/internal/bundle 214.495s coverage: 93.5% of statements in ./... ``` ``` helpers.go:163: [databricks stdout]: Hello from my func helpers.go:163: [databricks stdout]: Got arguments: helpers.go:163: [databricks stdout]: ['my_test_code', 'one', 'two'] ... Bundle remote directory is ***/.bundle/0ef67aaf-5960-4049-bf1d-dc9e29157421 Deleted snapshot file at /var/folders/nt/xjv68qzs45319w4k36dhpylc0000gp/T/TestAccPythonWheelTaskDeployAndRunWithoutWrapper2340216760/001/.databricks/bundle/default/sync-snapshots/edf0b322cee93b13.json Successfully deleted files! --- PASS: TestAccPythonWheelTaskDeployAndRunWithoutWrapper (192.36s) PASS coverage: 93.5% of statements in ./... ok github.com/databricks/cli/internal/bundle 195.130s coverage: 93.5% of statements in ./... ```
- Loading branch information
1 parent
83a49e4
commit 273a58e
Showing
9 changed files
with
226 additions
and
23 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,35 @@ | ||
package mutator | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/databricks/cli/bundle" | ||
) | ||
|
||
type ifMutator struct { | ||
condition func(*bundle.Bundle) bool | ||
onTrueMutator bundle.Mutator | ||
onFalseMutator bundle.Mutator | ||
} | ||
|
||
func If( | ||
condition func(*bundle.Bundle) bool, | ||
onTrueMutator bundle.Mutator, | ||
onFalseMutator bundle.Mutator, | ||
) bundle.Mutator { | ||
return &ifMutator{ | ||
condition, onTrueMutator, onFalseMutator, | ||
} | ||
} | ||
|
||
func (m *ifMutator) Apply(ctx context.Context, b *bundle.Bundle) error { | ||
if m.condition(b) { | ||
return bundle.Apply(ctx, b, m.onTrueMutator) | ||
} else { | ||
return bundle.Apply(ctx, b, m.onFalseMutator) | ||
} | ||
} | ||
|
||
func (m *ifMutator) Name() string { | ||
return "If" | ||
} |
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,21 @@ | ||
package mutator | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/databricks/cli/bundle" | ||
) | ||
|
||
type noop struct{} | ||
|
||
func (*noop) Apply(context.Context, *bundle.Bundle) error { | ||
return nil | ||
} | ||
|
||
func (*noop) Name() string { | ||
return "NoOp" | ||
} | ||
|
||
func NoOp() bundle.Mutator { | ||
return &noop{} | ||
} |
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,114 @@ | ||
package python | ||
|
||
import ( | ||
"context" | ||
"path" | ||
"path/filepath" | ||
"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/compute" | ||
"github.com/databricks/databricks-sdk-go/service/jobs" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNoTransformByDefault(t *testing.T) { | ||
tmpDir := t.TempDir() | ||
|
||
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Path: tmpDir, | ||
Bundle: config.Bundle{ | ||
Target: "development", | ||
}, | ||
Resources: config.Resources{ | ||
Jobs: map[string]*resources.Job{ | ||
"job1": { | ||
JobSettings: &jobs.JobSettings{ | ||
Tasks: []jobs.Task{ | ||
{ | ||
TaskKey: "key1", | ||
PythonWheelTask: &jobs.PythonWheelTask{ | ||
PackageName: "test_package", | ||
EntryPoint: "main", | ||
}, | ||
Libraries: []compute.Library{ | ||
{Whl: "/Workspace/Users/test@test.com/bundle/dist/test.whl"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
trampoline := TransformWheelTask() | ||
err := bundle.Apply(context.Background(), b, trampoline) | ||
require.NoError(t, err) | ||
|
||
task := b.Config.Resources.Jobs["job1"].Tasks[0] | ||
require.NotNil(t, task.PythonWheelTask) | ||
require.Equal(t, "test_package", task.PythonWheelTask.PackageName) | ||
require.Equal(t, "main", task.PythonWheelTask.EntryPoint) | ||
require.Equal(t, "/Workspace/Users/test@test.com/bundle/dist/test.whl", task.Libraries[0].Whl) | ||
|
||
require.Nil(t, task.NotebookTask) | ||
} | ||
|
||
func TestTransformWithExperimentalSettingSetToTrue(t *testing.T) { | ||
tmpDir := t.TempDir() | ||
|
||
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Path: tmpDir, | ||
Bundle: config.Bundle{ | ||
Target: "development", | ||
}, | ||
Resources: config.Resources{ | ||
Jobs: map[string]*resources.Job{ | ||
"job1": { | ||
JobSettings: &jobs.JobSettings{ | ||
Tasks: []jobs.Task{ | ||
{ | ||
TaskKey: "key1", | ||
PythonWheelTask: &jobs.PythonWheelTask{ | ||
PackageName: "test_package", | ||
EntryPoint: "main", | ||
}, | ||
Libraries: []compute.Library{ | ||
{Whl: "/Workspace/Users/test@test.com/bundle/dist/test.whl"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Experimental: &config.Experimental{ | ||
PythonWheelWrapper: true, | ||
}, | ||
}, | ||
} | ||
|
||
trampoline := TransformWheelTask() | ||
err := bundle.Apply(context.Background(), b, trampoline) | ||
require.NoError(t, err) | ||
|
||
task := b.Config.Resources.Jobs["job1"].Tasks[0] | ||
require.Nil(t, task.PythonWheelTask) | ||
require.NotNil(t, task.NotebookTask) | ||
|
||
dir, err := b.InternalDir(context.Background()) | ||
require.NoError(t, err) | ||
|
||
internalDirRel, err := filepath.Rel(b.Config.Path, dir) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, path.Join(filepath.ToSlash(internalDirRel), "notebook_job1_key1"), task.NotebookTask.NotebookPath) | ||
|
||
require.Empty(t, task.Libraries) | ||
} |
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
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