-
Notifications
You must be signed in to change notification settings - Fork 168
Raise an error when there are multiple local libraries with the same basename used #2297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8da4be9
Raise an error when there are multiple locallibraries with the same b…
andrewnester 7749d4e
added missing comment
andrewnester 893b10d
fixes
andrewnester 8625d0a
Merge remote-tracking branch 'origin/main' into fix/same-name-wheels
andrewnester 1b15c7d
added acc test
andrewnester File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,72 @@ | ||
| package libraries | ||
|
|
||
| import ( | ||
| "context" | ||
| "path/filepath" | ||
|
|
||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/libs/diag" | ||
| "github.com/databricks/cli/libs/dyn" | ||
| ) | ||
|
|
||
| type checkForSameNameLibraries struct{} | ||
|
|
||
| var patterns = []dyn.Pattern{ | ||
| taskLibrariesPattern.Append(dyn.AnyIndex(), dyn.AnyKey()), | ||
| forEachTaskLibrariesPattern.Append(dyn.AnyIndex(), dyn.AnyKey()), | ||
| envDepsPattern.Append(dyn.AnyIndex()), | ||
| } | ||
|
|
||
| func (c checkForSameNameLibraries) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { | ||
| var diags diag.Diagnostics | ||
| libBaseNames := make(map[string]bool) | ||
|
|
||
| err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) { | ||
| var err error | ||
| for _, pattern := range patterns { | ||
| v, err = dyn.MapByPattern(v, pattern, func(p dyn.Path, lv dyn.Value) (dyn.Value, error) { | ||
| libPath := lv.MustString() | ||
| // If not local library, skip the check | ||
| if !IsLibraryLocal(libPath) { | ||
| return lv, nil | ||
| } | ||
|
|
||
| lib := filepath.Base(lv.MustString()) | ||
| if libBaseNames[lib] { | ||
| diags = append(diags, diag.Diagnostic{ | ||
| Severity: diag.Error, | ||
| Summary: "Duplicate local library name", | ||
|
andrewnester marked this conversation as resolved.
Outdated
|
||
| Detail: "Local library names must be unique", | ||
| Locations: lv.Locations(), | ||
| Paths: []dyn.Path{p}, | ||
| }) | ||
| } | ||
|
|
||
| libBaseNames[lib] = true | ||
| return lv, nil | ||
| }) | ||
| if err != nil { | ||
| return dyn.InvalidValue, err | ||
| } | ||
| } | ||
|
|
||
| if err != nil { | ||
| return dyn.InvalidValue, err | ||
| } | ||
|
|
||
| return v, nil | ||
| }) | ||
| if err != nil { | ||
| diags = diags.Extend(diag.FromErr(err)) | ||
| } | ||
|
|
||
| return diags | ||
| } | ||
|
|
||
| func (c checkForSameNameLibraries) Name() string { | ||
| return "CheckForSameNameLibraries" | ||
| } | ||
|
|
||
| func CheckForSameNameLibraries() bundle.Mutator { | ||
| return checkForSameNameLibraries{} | ||
| } | ||
This file contains hidden or 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,92 @@ | ||
| package libraries | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/bundle/config" | ||
| "github.com/databricks/cli/bundle/config/resources" | ||
| "github.com/databricks/cli/libs/diag" | ||
| "github.com/databricks/databricks-sdk-go/service/compute" | ||
| "github.com/databricks/databricks-sdk-go/service/jobs" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestSameNameLibraries(t *testing.T) { | ||
| b := &bundle.Bundle{ | ||
| Config: config.Root{ | ||
| Resources: config.Resources{ | ||
| Jobs: map[string]*resources.Job{ | ||
| "test": { | ||
| JobSettings: &jobs.JobSettings{ | ||
| Tasks: []jobs.Task{ | ||
| { | ||
| Libraries: []compute.Library{ | ||
| { | ||
| Whl: "full/path/test.whl", | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| Libraries: []compute.Library{ | ||
| { | ||
| Whl: "other/path/test.whl", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| diags := bundle.Apply(context.Background(), b, CheckForSameNameLibraries()) | ||
| require.Len(t, diags, 1) | ||
| require.Equal(t, diag.Error, diags[0].Severity) | ||
| require.Equal(t, "Duplicate local library name", diags[0].Summary) | ||
|
andrewnester marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| func TestSameNameLibrariesWithUniqueLibraries(t *testing.T) { | ||
| b := &bundle.Bundle{ | ||
| Config: config.Root{ | ||
| Resources: config.Resources{ | ||
| Jobs: map[string]*resources.Job{ | ||
| "test": { | ||
| JobSettings: &jobs.JobSettings{ | ||
| Tasks: []jobs.Task{ | ||
| { | ||
| Libraries: []compute.Library{ | ||
| { | ||
| Whl: "full/path/test-0.1.1.whl", | ||
| }, | ||
|
|
||
| { | ||
| Whl: "cowsay", | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| Libraries: []compute.Library{ | ||
| { | ||
| Whl: "other/path/test-0.1.0.whl", | ||
| }, | ||
|
|
||
| { | ||
| Whl: "cowsay", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| diags := bundle.Apply(context.Background(), b, CheckForSameNameLibraries()) | ||
| require.Empty(t, diags) | ||
|
andrewnester marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.