diff --git a/bundle/deploy/files/sync.go b/bundle/deploy/files/sync.go index d0987d63..84d79dc8 100644 --- a/bundle/deploy/files/sync.go +++ b/bundle/deploy/files/sync.go @@ -15,9 +15,8 @@ func getSync(ctx context.Context, b *bundle.Bundle) (*sync.Sync, error) { } opts := sync.SyncOptions{ - LocalPath: b.Config.Path, - RemotePath: b.Config.Workspace.FilesPath, - + LocalPath: b.Config.Path, + RemotePath: b.Config.Workspace.FilesPath, Full: false, CurrentUser: b.Config.Workspace.CurrentUser.User, diff --git a/bundle/python/transform.go b/bundle/python/transform.go index 42a5cf6e..aa1a3db5 100644 --- a/bundle/python/transform.go +++ b/bundle/python/transform.go @@ -114,9 +114,14 @@ func generateNotebookWrapper(b *bundle.Bundle, task *jobs.PythonWheelTask, libra } defer f.Close() + params, err := generateParameters(task) + if err != nil { + return "", err + } + data := map[string]any{ "Libraries": libraries, - "Params": generateParameters(task), + "Params": params, "Task": task, } @@ -127,7 +132,10 @@ func generateNotebookWrapper(b *bundle.Bundle, task *jobs.PythonWheelTask, libra return notebookName, t.Execute(f, data) } -func generateParameters(task *jobs.PythonWheelTask) string { +func generateParameters(task *jobs.PythonWheelTask) (string, error) { + if task.Parameters != nil && task.NamedParameters != nil { + return "", fmt.Errorf("not allowed to pass both paramaters and named_parameters") + } params := append([]string{"python"}, task.Parameters...) for k, v := range task.NamedParameters { params = append(params, fmt.Sprintf("%s=%s", k, v)) @@ -135,5 +143,5 @@ func generateParameters(task *jobs.PythonWheelTask) string { for i := range params { params[i] = `"` + params[i] + `"` } - return strings.Join(params, ", ") + return strings.Join(params, ", "), nil } diff --git a/bundle/python/transform_test.go b/bundle/python/transform_test.go new file mode 100644 index 00000000..6b3c5f55 --- /dev/null +++ b/bundle/python/transform_test.go @@ -0,0 +1,55 @@ +package python + +import ( + "testing" + + "github.com/databricks/databricks-sdk-go/service/jobs" + "github.com/stretchr/testify/require" +) + +type testCase struct { + Actual []string + Expected string +} +type NamedParams map[string]string +type testCaseNamed struct { + Actual NamedParams + Expected string +} + +var paramsTestCases []testCase = []testCase{ + {[]string{}, `"python"`}, + {[]string{"a"}, `"python", "a"`}, + {[]string{"a", "b"}, `"python", "a", "b"`}, + {[]string{"123!@#$%^&*()-="}, `"python", "123!@#$%^&*()-="`}, +} + +var paramsTestCasesNamed []testCaseNamed = []testCaseNamed{ + {NamedParams{}, `"python"`}, + {NamedParams{"a": "1"}, `"python", "a=1"`}, + {NamedParams{"a": "1", "b": "2"}, `"python", "a=1", "b=2"`}, +} + +func TestGenerateParameters(t *testing.T) { + for _, c := range paramsTestCases { + task := &jobs.PythonWheelTask{Parameters: c.Actual} + result, err := generateParameters(task) + require.NoError(t, err) + require.Equal(t, c.Expected, result) + } +} + +func TestGenerateNamedParameters(t *testing.T) { + for _, c := range paramsTestCasesNamed { + task := &jobs.PythonWheelTask{NamedParameters: c.Actual} + result, err := generateParameters(task) + require.NoError(t, err) + require.Equal(t, c.Expected, result) + } +} + +func TestGenerateBoth(t *testing.T) { + task := &jobs.PythonWheelTask{NamedParameters: map[string]string{"a": "1"}, Parameters: []string{"b"}} + _, err := generateParameters(task) + require.Error(t, err) +} diff --git a/cmd/sync/sync.go b/cmd/sync/sync.go index a9380b75..d2aad0c3 100644 --- a/cmd/sync/sync.go +++ b/cmd/sync/sync.go @@ -36,9 +36,8 @@ func (f *syncFlags) syncOptionsFromBundle(cmd *cobra.Command, args []string, b * } opts := sync.SyncOptions{ - LocalPath: b.Config.Path, - RemotePath: b.Config.Workspace.FilesPath, - + LocalPath: b.Config.Path, + RemotePath: b.Config.Workspace.FilesPath, Full: f.full, PollInterval: f.interval, diff --git a/libs/fileset/glob.go b/libs/fileset/glob.go deleted file mode 100644 index 8593ae86..00000000 --- a/libs/fileset/glob.go +++ /dev/null @@ -1,45 +0,0 @@ -package fileset - -import ( - "io/fs" - "os" - "path/filepath" -) - -type GlobSet struct { - root string - patterns []string -} - -func NewGlobSet(root string, includes []string) *GlobSet { - return &GlobSet{root, includes} -} - -// Return all tracked files for Repo -func (s *GlobSet) All() ([]File, error) { - files := make([]File, 0) - for _, pattern := range s.patterns { - matches, err := filepath.Glob(pattern) - if err != nil { - return files, err - } - - for _, match := range matches { - if !filepath.IsAbs(match) { - match = filepath.Join(s.root, match) - } - matchRel, err := filepath.Rel(s.root, match) - if err != nil { - return files, err - } - - stat, err := os.Stat(match) - if err != nil { - return files, err - } - files = append(files, File{fs.FileInfoToDirEntry(stat), match, matchRel}) - } - } - - return files, nil -} diff --git a/libs/sync/sync.go b/libs/sync/sync.go index 4dc03c57..a299214d 100644 --- a/libs/sync/sync.go +++ b/libs/sync/sync.go @@ -32,8 +32,7 @@ type SyncOptions struct { type Sync struct { *SyncOptions - fileSet *git.FileSet - + fileSet *git.FileSet snapshot *Snapshot filer filer.Filer