github.com/databricks/cli@v0.203.0/bundle/artifacts/whl/build.go (about) 1 package whl 2 3 import ( 4 "context" 5 "fmt" 6 "os" 7 "path/filepath" 8 9 "github.com/databricks/cli/bundle" 10 "github.com/databricks/cli/bundle/config" 11 "github.com/databricks/cli/libs/cmdio" 12 "github.com/databricks/cli/python" 13 ) 14 15 type build struct { 16 name string 17 } 18 19 func Build(name string) bundle.Mutator { 20 return &build{ 21 name: name, 22 } 23 } 24 25 func (m *build) Name() string { 26 return fmt.Sprintf("artifacts.whl.Build(%s)", m.name) 27 } 28 29 func (m *build) Apply(ctx context.Context, b *bundle.Bundle) error { 30 artifact, ok := b.Config.Artifacts[m.name] 31 if !ok { 32 return fmt.Errorf("artifact doesn't exist: %s", m.name) 33 } 34 35 cmdio.LogString(ctx, fmt.Sprintf("artifacts.whl.Build(%s): Building...", m.name)) 36 37 dir := artifact.Path 38 39 distPath := filepath.Join(dir, "dist") 40 os.RemoveAll(distPath) 41 python.CleanupWheelFolder(dir) 42 43 out, err := artifact.Build(ctx) 44 if err != nil { 45 return fmt.Errorf("artifacts.whl.Build(%s): Failed %w, output: %s", m.name, err, out) 46 } 47 cmdio.LogString(ctx, fmt.Sprintf("artifacts.whl.Build(%s): Build succeeded", m.name)) 48 49 wheels := python.FindFilesWithSuffixInPath(distPath, ".whl") 50 if len(wheels) == 0 { 51 return fmt.Errorf("artifacts.whl.Build(%s): cannot find built wheel in %s", m.name, dir) 52 } 53 for _, wheel := range wheels { 54 artifact.Files = append(artifact.Files, config.ArtifactFile{ 55 Source: wheel, 56 }) 57 } 58 59 return nil 60 }