mirror of https://github.com/databricks/cli.git
feat: Use path translations instead of overriding config
This commit is contained in:
parent
518aa14b64
commit
aeb9813d25
|
@ -223,11 +223,8 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
|
|||
}
|
||||
|
||||
if config.IsExplicitlyEnabled((b.Config.Presets.SourceLinkedDeployment)) {
|
||||
root := b.SyncRootPath
|
||||
isInWorkspace := strings.HasPrefix(root, "/Workspace/")
|
||||
if isInWorkspace && dbr.RunsOnRuntime(ctx) {
|
||||
b.Config.Workspace.FilePath = root
|
||||
} else {
|
||||
isDatabricksWorkspace := dbr.RunsOnRuntime(ctx) && strings.HasPrefix(b.SyncRootPath, "/Workspace/")
|
||||
if !isDatabricksWorkspace {
|
||||
disabled := false
|
||||
b.Config.Presets.SourceLinkedDeployment = &disabled
|
||||
diags = diags.Extend(diag.Warningf("source-linked deployment is available only in the Databricks Workspace"))
|
||||
|
|
|
@ -377,7 +377,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
|||
testContext := context.Background()
|
||||
enabled := true
|
||||
disabled := false
|
||||
remotePath := "/Users/files"
|
||||
workspacePath := "/Workspace/user.name@company.com"
|
||||
|
||||
tests := []struct {
|
||||
|
@ -386,7 +385,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
|||
name string
|
||||
initialValue *bool
|
||||
expectedValue *bool
|
||||
expectedFilePath string
|
||||
expectedWarning string
|
||||
}{
|
||||
{
|
||||
|
@ -395,8 +393,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
|||
ctx: dbr.MockRuntime(testContext, true),
|
||||
initialValue: &enabled,
|
||||
expectedValue: &enabled,
|
||||
expectedFilePath: workspacePath,
|
||||
expectedWarning: "",
|
||||
},
|
||||
{
|
||||
name: "preset enabled, bundle not in Workspace, databricks runtime",
|
||||
|
@ -404,7 +400,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
|||
ctx: dbr.MockRuntime(testContext, true),
|
||||
initialValue: &enabled,
|
||||
expectedValue: &disabled,
|
||||
expectedFilePath: remotePath,
|
||||
expectedWarning: "source-linked deployment is available only in the Databricks Workspace",
|
||||
},
|
||||
{
|
||||
|
@ -413,7 +408,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
|||
ctx: dbr.MockRuntime(testContext, false),
|
||||
initialValue: &enabled,
|
||||
expectedValue: &disabled,
|
||||
expectedFilePath: remotePath,
|
||||
expectedWarning: "source-linked deployment is available only in the Databricks Workspace",
|
||||
},
|
||||
{
|
||||
|
@ -422,7 +416,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
|||
ctx: dbr.MockRuntime(testContext, true),
|
||||
initialValue: &disabled,
|
||||
expectedValue: &disabled,
|
||||
expectedFilePath: remotePath,
|
||||
},
|
||||
{
|
||||
name: "preset nil, bundle in Workspace, databricks runtime",
|
||||
|
@ -430,22 +423,17 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
|||
ctx: dbr.MockRuntime(testContext, true),
|
||||
initialValue: nil,
|
||||
expectedValue: nil,
|
||||
expectedFilePath: remotePath,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
b := &bundle.Bundle{
|
||||
SyncRoot: vfs.MustNew(tt.bundlePath),
|
||||
SyncRootPath: tt.bundlePath,
|
||||
Config: config.Root{
|
||||
Presets: config.Presets{
|
||||
SourceLinkedDeployment: tt.initialValue,
|
||||
},
|
||||
Workspace: config.Workspace{
|
||||
FilePath: remotePath,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -458,7 +446,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
|||
require.Equal(t, tt.expectedWarning, diags[0].Summary)
|
||||
}
|
||||
|
||||
require.Equal(t, tt.expectedFilePath, b.Config.Workspace.FilePath)
|
||||
require.Equal(t, tt.expectedValue, b.Config.Presets.SourceLinkedDeployment)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -524,14 +524,12 @@ func TestSourceLinkedDeploymentEnabled(t *testing.T) {
|
|||
b, diags := processSourceLinkedBundle(t, true)
|
||||
require.NoError(t, diags.Error())
|
||||
assert.True(t, *b.Config.Presets.SourceLinkedDeployment)
|
||||
assert.Equal(t, b.Config.Workspace.FilePath, b.SyncRootPath)
|
||||
}
|
||||
|
||||
func TestSourceLinkedDeploymentDisabled(t *testing.T) {
|
||||
b, diags := processSourceLinkedBundle(t, false)
|
||||
require.NoError(t, diags.Error())
|
||||
assert.False(t, *b.Config.Presets.SourceLinkedDeployment)
|
||||
assert.NotEqual(t, b.Config.Workspace.FilePath, b.SyncRootPath)
|
||||
}
|
||||
|
||||
func processSourceLinkedBundle(t *testing.T, presetEnabled bool) (*bundle.Bundle, diag.Diagnostics) {
|
||||
|
@ -542,7 +540,6 @@ func processSourceLinkedBundle(t *testing.T, presetEnabled bool) (*bundle.Bundle
|
|||
b := mockBundle(config.Development)
|
||||
|
||||
workspacePath := "/Workspace/lennart@company.com/"
|
||||
b.SyncRoot = vfs.MustNew(workspacePath)
|
||||
b.SyncRootPath = workspacePath
|
||||
b.Config.Presets.SourceLinkedDeployment = &presetEnabled
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/databricks/cli/bundle"
|
||||
"github.com/databricks/cli/bundle/config"
|
||||
"github.com/databricks/cli/libs/diag"
|
||||
"github.com/databricks/cli/libs/dyn"
|
||||
"github.com/databricks/cli/libs/notebook"
|
||||
|
@ -103,8 +104,13 @@ func (t *translateContext) rewritePath(
|
|||
return fmt.Errorf("path %s is not contained in sync root path", localPath)
|
||||
}
|
||||
|
||||
// Prefix remote path with its remote root path.
|
||||
remotePath := path.Join(t.b.Config.Workspace.FilePath, filepath.ToSlash(localRelPath))
|
||||
var workspacePath string
|
||||
if config.IsExplicitlyEnabled(t.b.Config.Presets.SourceLinkedDeployment) {
|
||||
workspacePath = t.b.SyncRootPath
|
||||
} else {
|
||||
workspacePath = t.b.Config.Workspace.FilePath
|
||||
}
|
||||
remotePath := path.Join(workspacePath, filepath.ToSlash(localRelPath))
|
||||
|
||||
// Convert local path into workspace path via specified function.
|
||||
interp, err := fn(*p, localPath, localRelPath, remotePath)
|
||||
|
|
Loading…
Reference in New Issue