Skip to content

Commit b3ab621

Browse files
authored
Move artifacts clean up back to deploy phase (#2722)
## Changes - Move artifacts clean up procedure to "bundle deploy". This reverts change in behaviour introduced in 0.245.0 #2526 ## Why We don't expect major changes on the file system during "validate", it should be as much as possible about reporting issues with the bundle without taking action. ## Tests Existing tests.
1 parent 6e94e91 commit b3ab621

4 files changed

Lines changed: 41 additions & 21 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
### Bundles
1212
* Do not exit early when checking incompatible tasks for specified DBR ([#2692](https://github.com/databricks/cli/pull/2692))
1313
* Removed include/exclude flags support from bundle sync command ([#2718](https://github.com/databricks/cli/pull/2718))
14+
* Do not clean up Python artifacts dist and build folder in "bundle validate", do it in "bundle deploy". This reverts the behaviour introduced in 0.245.0 ([#2722](https://github.com/databricks/cli/pull/2722))
1415

1516
### API Changes

bundle/artifacts/build.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ func (m *build) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
3939
})
4040
}
4141

42+
cleanupPythonDistBuild(ctx, b)
43+
4244
for _, artifactName := range utils.SortedKeys(b.Config.Artifacts) {
4345
a := b.Config.Artifacts[artifactName]
4446

bundle/artifacts/cleanup.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package artifacts
2+
3+
import (
4+
"context"
5+
"os"
6+
"path/filepath"
7+
8+
"github.com/databricks/cli/bundle"
9+
"github.com/databricks/cli/libs/log"
10+
"github.com/databricks/cli/libs/python"
11+
"github.com/databricks/cli/libs/utils"
12+
)
13+
14+
func cleanupPythonDistBuild(ctx context.Context, b *bundle.Bundle) {
15+
removeFolders := make(map[string]bool, len(b.Config.Artifacts))
16+
cleanupWheelFolders := make(map[string]bool, len(b.Config.Artifacts))
17+
18+
for _, artifactName := range utils.SortedKeys(b.Config.Artifacts) {
19+
artifact := b.Config.Artifacts[artifactName]
20+
if artifact.Type == "whl" && artifact.BuildCommand != "" {
21+
dir := artifact.Path
22+
removeFolders[filepath.Join(dir, "dist")] = true
23+
cleanupWheelFolders[dir] = true
24+
}
25+
}
26+
27+
for _, dir := range utils.SortedKeys(removeFolders) {
28+
err := os.RemoveAll(dir)
29+
if err != nil {
30+
log.Infof(ctx, "Failed to remove %s: %s", dir, err)
31+
}
32+
}
33+
34+
for _, dir := range utils.SortedKeys(cleanupWheelFolders) {
35+
log.Infof(ctx, "Cleaning up Python build artifacts in %s", dir)
36+
python.CleanupWheelFolder(dir)
37+
}
38+
}

bundle/artifacts/prepare.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ func (m *prepare) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
3333
return diag.FromErr(err)
3434
}
3535

36-
removeFolders := make(map[string]bool, len(b.Config.Artifacts))
37-
cleanupWheelFolders := make(map[string]bool, len(b.Config.Artifacts))
38-
3936
for _, artifactName := range utils.SortedKeys(b.Config.Artifacts) {
4037
artifact := b.Config.Artifacts[artifactName]
4138
b.Metrics.AddBoolValue(metrics.ArtifactBuildCommandIsSet, artifact.BuildCommand != "")
@@ -66,12 +63,6 @@ func (m *prepare) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
6663
artifact.Path = filepath.Join(dirPath, artifact.Path)
6764
}
6865

69-
if artifact.Type == "whl" && artifact.BuildCommand != "" {
70-
dir := artifact.Path
71-
removeFolders[filepath.Join(dir, "dist")] = true
72-
cleanupWheelFolders[dir] = true
73-
}
74-
7566
if artifact.BuildCommand == "" && len(artifact.Files) == 0 {
7667
diags = diags.Extend(diag.Errorf("misconfigured artifact: please specify 'build' or 'files' property"))
7768
}
@@ -89,18 +80,6 @@ func (m *prepare) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
8980
return diags
9081
}
9182

92-
for _, dir := range utils.SortedKeys(removeFolders) {
93-
err := os.RemoveAll(dir)
94-
if err != nil {
95-
log.Infof(ctx, "Failed to remove %s: %s", dir, err)
96-
}
97-
}
98-
99-
for _, dir := range utils.SortedKeys(cleanupWheelFolders) {
100-
log.Infof(ctx, "Cleaning up Python build artifacts in %s", dir)
101-
python.CleanupWheelFolder(dir)
102-
}
103-
10483
return diags
10584
}
10685

0 commit comments

Comments
 (0)