Skip to content

Commit c7771a8

Browse files
authored
Remove direct dependency on golang.org/x/exp (#4944)
## Summary - Replace all `golang.org/x/exp/maps` usage with stdlib equivalents (`maps` and `slices` packages) - `maps.Clone`/`maps.Copy` are drop-in replacements (Go 1.21+) - `maps.Keys`/`maps.Values` return iterators in stdlib (Go 1.23+), so slice-consuming call sites are wrapped with `slices.Collect` - Remove `golang.org/x/exp` from NOTICE file; it remains as an indirect dependency through databricks-sdk-go This pull request was AI-assisted by Isaac.
1 parent eacf329 commit c7771a8

26 files changed

Lines changed: 75 additions & 66 deletions

File tree

NOTICE

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ golang.org/x/crypto - https://github.com/golang/crypto
9999
Copyright 2009 The Go Authors.
100100
License - https://github.com/golang/crypto/blob/master/LICENSE
101101

102-
golang.org/x/exp - https://github.com/golang/exp
103-
Copyright 2009 The Go Authors.
104-
License - https://github.com/golang/exp/blob/master/LICENSE
105-
106102
golang.org/x/mod - https://github.com/golang/mod
107103
Copyright 2009 The Go Authors.
108104
License - https://github.com/golang/mod/blob/master/LICENSE

bundle/config/mutator/python/python_mutator_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ package python
33
import (
44
"context"
55
"fmt"
6+
"maps"
67
"os"
78
"os/exec"
89
"path/filepath"
910
"runtime"
11+
"slices"
1012
"testing"
1113

1214
"github.com/databricks/cli/libs/dyn/convert"
1315

1416
"github.com/databricks/cli/bundle/env"
1517
"github.com/stretchr/testify/require"
1618

17-
"golang.org/x/exp/maps"
18-
1919
"github.com/databricks/cli/libs/dyn"
2020

2121
"github.com/databricks/cli/bundle"
@@ -103,7 +103,7 @@ workspace: { current_user: { userName: test }}`)
103103

104104
assert.NoError(t, diags.Error())
105105

106-
assert.ElementsMatch(t, []string{"job0", "job1"}, maps.Keys(b.Config.Resources.Jobs))
106+
assert.ElementsMatch(t, []string{"job0", "job1"}, slices.Collect(maps.Keys(b.Config.Resources.Jobs)))
107107

108108
if job0, ok := b.Config.Resources.Jobs["job0"]; ok {
109109
assert.Equal(t, "job_0", job0.Name)
@@ -212,7 +212,7 @@ resources:
212212

213213
assert.NoError(t, diag.Error())
214214

215-
assert.ElementsMatch(t, []string{"job0"}, maps.Keys(b.Config.Resources.Jobs))
215+
assert.ElementsMatch(t, []string{"job0"}, slices.Collect(maps.Keys(b.Config.Resources.Jobs)))
216216
assert.Equal(t, "job_0", b.Config.Resources.Jobs["job0"].Name)
217217
assert.Equal(t, "my job", b.Config.Resources.Jobs["job0"].Description)
218218

bundle/config/mutator/select_default_target.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package mutator
22

33
import (
44
"context"
5+
"maps"
6+
"slices"
57
"strings"
68

79
"github.com/databricks/cli/bundle"
810
"github.com/databricks/cli/libs/diag"
9-
"golang.org/x/exp/maps"
1011
)
1112

1213
type selectDefaultTarget struct{}
@@ -26,7 +27,7 @@ func (m *selectDefaultTarget) Apply(ctx context.Context, b *bundle.Bundle) diag.
2627
}
2728

2829
// One target means there's only one default.
29-
names := maps.Keys(b.Config.Targets)
30+
names := slices.Collect(maps.Keys(b.Config.Targets))
3031
if len(names) == 1 {
3132
bundle.ApplyContext(ctx, b, SelectTarget(names[0]))
3233
return nil

bundle/config/mutator/select_target.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package mutator
33
import (
44
"context"
55
"fmt"
6+
"maps"
7+
"slices"
68
"strings"
79

810
"github.com/databricks/cli/bundle"
911
"github.com/databricks/cli/libs/diag"
10-
"golang.org/x/exp/maps"
1112
)
1213

1314
type selectTarget struct {
@@ -34,7 +35,7 @@ func (m *selectTarget) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnosti
3435
// Get specified target
3536
target, ok := b.Config.Targets[m.name]
3637
if !ok {
37-
return diag.Errorf("%s: no such target. Available targets: %s", m.name, strings.Join(maps.Keys(b.Config.Targets), ", "))
38+
return diag.Errorf("%s: no such target. Available targets: %s", m.name, strings.Join(slices.Collect(maps.Keys(b.Config.Targets)), ", "))
3839
}
3940

4041
// Merge specified target into root configuration structure.

bundle/deploy/terraform/init.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import (
55
"errors"
66
"fmt"
77
"io/fs"
8+
"maps"
89
"os"
910
"os/exec"
1011
"path/filepath"
1112
"runtime"
13+
"slices"
1214
"strings"
1315

1416
"github.com/databricks/cli/bundle"
@@ -20,7 +22,6 @@ import (
2022
"github.com/databricks/cli/libs/log"
2123
"github.com/hashicorp/hc-install/product"
2224
"github.com/hashicorp/terraform-exec/tfexec"
23-
"golang.org/x/exp/maps"
2425
)
2526

2627
func findExecPath(ctx context.Context, b *bundle.Bundle, tf *config.Terraform, installer Installer) (string, error) {
@@ -363,7 +364,7 @@ func Initialize(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
363364
}
364365

365366
// Configure environment variables for auth for Terraform to use.
366-
log.Debugf(ctx, "Environment variables for Terraform: %s", strings.Join(maps.Keys(environ), ", "))
367+
log.Debugf(ctx, "Environment variables for Terraform: %s", strings.Join(slices.Collect(maps.Keys(environ)), ", "))
367368
err = tfe.SetEnv(environ)
368369
if err != nil {
369370
return diag.FromErr(err)

bundle/deploy/terraform/init_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package terraform
33
import (
44
"context"
55
"fmt"
6+
"maps"
67
"os"
78
"path/filepath"
89
"runtime"
10+
"slices"
911
"strings"
1012
"testing"
1113

@@ -18,7 +20,6 @@ import (
1820
"github.com/hashicorp/hc-install/product"
1921
"github.com/stretchr/testify/assert"
2022
"github.com/stretchr/testify/require"
21-
"golang.org/x/exp/maps"
2223
)
2324

2425
func unsetEnv(t *testing.T, name string) {
@@ -208,7 +209,7 @@ func TestSetProxyEnvVars(t *testing.T) {
208209
env = make(map[string]string, 0)
209210
err = setProxyEnvVars(t.Context(), env, b)
210211
require.NoError(t, err)
211-
assert.ElementsMatch(t, []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"}, maps.Keys(env))
212+
assert.ElementsMatch(t, []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"}, slices.Collect(maps.Keys(env)))
212213

213214
// Upper case set.
214215
clearEnv()
@@ -218,7 +219,7 @@ func TestSetProxyEnvVars(t *testing.T) {
218219
env = make(map[string]string, 0)
219220
err = setProxyEnvVars(t.Context(), env, b)
220221
require.NoError(t, err)
221-
assert.ElementsMatch(t, []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"}, maps.Keys(env))
222+
assert.ElementsMatch(t, []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"}, slices.Collect(maps.Keys(env)))
222223
}
223224

224225
func TestSetUserAgentExtra_Python(t *testing.T) {
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package generator
22

33
import (
4+
"maps"
45
"slices"
5-
6-
"golang.org/x/exp/maps"
76
)
87

98
// sortKeys returns a sorted copy of the keys in the specified map.
109
func sortKeys[M ~map[K]V, K string, V any](m M) []K {
11-
keys := maps.Keys(m)
10+
keys := slices.Collect(maps.Keys(m))
1211
slices.Sort(keys)
1312
return keys
1413
}

bundle/internal/tf/codegen/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/hashicorp/terraform-json v0.27.2
1212
github.com/iancoleman/strcase v0.3.0
1313
github.com/zclconf/go-cty v1.16.4
14-
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6
1514
)
1615

1716
require (

bundle/internal/tf/codegen/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ github.com/zclconf/go-cty v1.16.4 h1:QGXaag7/7dCzb+odlGrgr+YmYZFaOCMW6DEpS+UD1eE
6262
github.com/zclconf/go-cty v1.16.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
6363
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
6464
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
65-
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6 h1:zfMcR1Cs4KNuomFFgGefv5N0czO2XZpUbxGUy8i8ug0=
66-
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6/go.mod h1:46edojNIoXTNOhySWIWdix628clX9ODXwPsQuG6hsK0=
6765
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
6866
golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
6967
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=

bundle/run/job_args.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package run
22

33
import (
4+
"maps"
5+
"slices"
6+
47
"github.com/databricks/cli/bundle/config/resources"
58
"github.com/spf13/cobra"
6-
"golang.org/x/exp/maps"
79
)
810

911
type jobParameterArgs struct {
@@ -63,7 +65,7 @@ func (a jobTaskNotebookParamArgs) CompleteArgs(args []string, toComplete string)
6365
maps.Copy(parameters, nt.BaseParameters)
6466
}
6567
}
66-
return genericCompleteKeyValueArgs(args, toComplete, maps.Keys(parameters))
68+
return genericCompleteKeyValueArgs(args, toComplete, slices.Collect(maps.Keys(parameters)))
6769
}
6870

6971
type jobTaskJarParamArgs struct {
@@ -163,7 +165,7 @@ func (r *jobRunner) posArgsHandler() argsHandler {
163165
}
164166

165167
// Cannot handle positional arguments if we have more than one task type.
166-
keys := maps.Keys(seen)
168+
keys := slices.Collect(maps.Keys(seen))
167169
if len(keys) != 1 {
168170
return nopArgsHandler{}
169171
}

0 commit comments

Comments
 (0)