Skip to content

Commit 98e9d4a

Browse files
authored
Rename CacheDir to LocalStateDir (#3194)
## Changes <!-- Brief summary of your changes that is easy to understand --> 1. Rename `CacheDir` interface to `LocalStateDir` 2. Rename tests that mention `CacheDir` so that they mention `LocalStateDir` now ## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> `CacheDir` is a term that is not semantically correct since it contains not only cache, but also the state of the bundle. ## Tests <!-- How have you tested the changes? --> Existing tests are passing <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 897d965 commit 98e9d4a

File tree

11 files changed

+22
-22
lines changed

11 files changed

+22
-22
lines changed

bundle/artifacts/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (m *build) Name() string {
2929
}
3030

3131
func (m *build) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
32-
cacheDir, err := b.CacheDir(ctx)
32+
cacheDir, err := b.LocalStateDir(ctx)
3333
if err != nil {
3434
logdiag.LogDiag(ctx, diag.Diagnostic{
3535
Severity: diag.Warning,

bundle/bundle.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ func (b *Bundle) SetWorkpaceClient(w *databricks.WorkspaceClient) {
217217
b.client = w
218218
}
219219

220-
// CacheDir returns directory to use for temporary files for this bundle.
220+
// LocalStateDir returns directory to use for temporary files for this bundle.
221221
// Scoped to the bundle's target.
222-
func (b *Bundle) CacheDir(ctx context.Context, paths ...string) (string, error) {
222+
func (b *Bundle) LocalStateDir(ctx context.Context, paths ...string) (string, error) {
223223
if b.Config.Bundle.Target == "" {
224224
panic("target not set")
225225
}
@@ -259,7 +259,7 @@ func (b *Bundle) CacheDir(ctx context.Context, paths ...string) (string, error)
259259
// This directory is used to store and automaticaly sync internal bundle files, such as, f.e
260260
// notebook trampoline files for Python wheel and etc.
261261
func (b *Bundle) InternalDir(ctx context.Context) (string, error) {
262-
cacheDir, err := b.CacheDir(ctx)
262+
cacheDir, err := b.LocalStateDir(ctx)
263263
if err != nil {
264264
return "", err
265265
}
@@ -346,13 +346,13 @@ func (b *Bundle) StateFilename() string {
346346

347347
func (b *Bundle) StateLocalPath(ctx context.Context) (string, error) {
348348
if b.DirectDeployment {
349-
cacheDir, err := b.CacheDir(ctx)
349+
cacheDir, err := b.LocalStateDir(ctx)
350350
if err != nil {
351351
return "", err
352352
}
353353
return filepath.Join(cacheDir, resourcesFilename), nil
354354
} else {
355-
cacheDir, err := b.CacheDir(ctx, "terraform")
355+
cacheDir, err := b.LocalStateDir(ctx, "terraform")
356356
if err != nil {
357357
return "", err
358358
}

bundle/bundle_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestLoadExists(t *testing.T) {
5050
assert.NotNil(t, b)
5151
}
5252

53-
func TestBundleCacheDir(t *testing.T) {
53+
func TestBundleLocalStateDir(t *testing.T) {
5454
ctx := context.Background()
5555
projectDir := t.TempDir()
5656
f1, err := os.Create(filepath.Join(projectDir, "databricks.yml"))
@@ -67,14 +67,14 @@ func TestBundleCacheDir(t *testing.T) {
6767
// unset env variable in case it's set
6868
t.Setenv("DATABRICKS_BUNDLE_TMP", "")
6969

70-
cacheDir, err := bundle.CacheDir(ctx)
70+
cacheDir, err := bundle.LocalStateDir(ctx)
7171

7272
// format is <CWD>/.databricks/bundle/<target>
7373
assert.NoError(t, err)
7474
assert.Equal(t, filepath.Join(projectDir, ".databricks", "bundle", "default"), cacheDir)
7575
}
7676

77-
func TestBundleCacheDirOverride(t *testing.T) {
77+
func TestBundleLocalStateDirOverride(t *testing.T) {
7878
ctx := context.Background()
7979
projectDir := t.TempDir()
8080
bundleTmpDir := t.TempDir()
@@ -92,7 +92,7 @@ func TestBundleCacheDirOverride(t *testing.T) {
9292
// now we expect to use 'bundleTmpDir' instead of CWD/.databricks/bundle
9393
t.Setenv("DATABRICKS_BUNDLE_TMP", bundleTmpDir)
9494

95-
cacheDir, err := bundle.CacheDir(ctx)
95+
cacheDir, err := bundle.LocalStateDir(ctx)
9696

9797
// format is <DATABRICKS_BUNDLE_TMP>/<target>
9898
assert.NoError(t, err)

bundle/config/mutator/python/python_mutator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ func (m *pythonMutator) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagno
241241
}
242242

243243
func createCacheDir(ctx context.Context) (string, error) {
244-
// b.CacheDir doesn't work because target isn't yet selected
244+
// b.LocalStateDir doesn't work because target isn't yet selected
245245

246-
// support the same env variable as in b.CacheDir
246+
// support the same env variable as in b.LocalStateDir
247247
if tempDir, exists := env.TempDir(ctx); exists {
248248
// use 'default' as target name
249249
cacheDir := filepath.Join(tempDir, "default", "python")

bundle/deploy/files/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func GetSync(ctx context.Context, b *bundle.Bundle) (*sync.Sync, error) {
1717
}
1818

1919
func GetSyncOptions(ctx context.Context, b *bundle.Bundle) (*sync.SyncOptions, error) {
20-
cacheDir, err := b.CacheDir(ctx)
20+
cacheDir, err := b.LocalStateDir(ctx)
2121
if err != nil {
2222
return nil, fmt.Errorf("cannot get bundle cache directory: %w", err)
2323
}

bundle/deploy/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func loadState(r io.Reader) (*DeploymentState, error) {
178178
}
179179

180180
func getPathToStateFile(ctx context.Context, b *bundle.Bundle) (string, error) {
181-
cacheDir, err := b.CacheDir(ctx)
181+
cacheDir, err := b.LocalStateDir(ctx)
182182
if err != nil {
183183
return "", fmt.Errorf("cannot get bundle cache directory: %w", err)
184184
}

bundle/deploy/terraform/dir.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ import (
99
// Dir returns the Terraform working directory for a given bundle.
1010
// The working directory is emphemeral and nested under the bundle's cache directory.
1111
func Dir(ctx context.Context, b *bundle.Bundle) (string, error) {
12-
return b.CacheDir(ctx, "terraform")
12+
return b.LocalStateDir(ctx, "terraform")
1313
}

bundle/deploy/terraform/init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (m *initialize) findExecPath(ctx context.Context, b *bundle.Bundle, tf *con
9191
return tf.ExecPath, nil
9292
}
9393

94-
binDir, err := b.CacheDir(ctx, "bin")
94+
binDir, err := b.LocalStateDir(ctx, "bin")
9595
if err != nil {
9696
return "", err
9797
}
@@ -243,7 +243,7 @@ func setTempDirEnvVars(ctx context.Context, environ map[string]string, b *bundle
243243
} else if v, ok := env.Lookup(ctx, "TEMP"); ok {
244244
environ["TEMP"] = v
245245
} else {
246-
tmpDir, err := b.CacheDir(ctx, "tmp")
246+
tmpDir, err := b.LocalStateDir(ctx, "tmp")
247247
if err != nil {
248248
return err
249249
}

bundle/deploy/terraform/init_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ func TestSetTempDirEnvVarsForWindowsWithoutAnyTempDirEnvVarsSet(t *testing.T) {
194194
err := setTempDirEnvVars(context.Background(), env, b)
195195
require.NoError(t, err)
196196

197-
// assert TMP is set to b.CacheDir("tmp")
198-
tmpDir, err := b.CacheDir(context.Background(), "tmp")
197+
// assert TMP is set to b.LocalStateDir("tmp")
198+
tmpDir, err := b.LocalStateDir(context.Background(), "tmp")
199199
require.NoError(t, err)
200200
assert.Equal(t, map[string]string{
201201
"TMP": tmpDir,
@@ -456,7 +456,7 @@ func TestFindExecPath_UseExistingBinary(t *testing.T) {
456456
}
457457

458458
// Create a pre-existing Terraform binary to avoid downloading it
459-
cacheDir, _ := b.CacheDir(ctx, "bin")
459+
cacheDir, _ := b.LocalStateDir(ctx, "bin")
460460
createFakeTerraformBinary(t, cacheDir, "1.2.3")
461461

462462
// Verify that the pre-existing Terraform binary is used.

bundle/statemgmt/state_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func identityFiler(f filer.Filer) deploy.FilerFactory {
2121
}
2222

2323
func localStateFile(t *testing.T, ctx context.Context, b *bundle.Bundle) string {
24-
dir, err := b.CacheDir(ctx, "terraform")
24+
dir, err := b.LocalStateDir(ctx, "terraform")
2525
require.NoError(t, err)
2626
return filepath.Join(dir, b.StateFilename())
2727
}

0 commit comments

Comments
 (0)