2023-07-25 11:35:08 +00:00
|
|
|
package whl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
|
|
|
"github.com/databricks/cli/libs/cmdio"
|
2024-03-25 14:18:47 +00:00
|
|
|
"github.com/databricks/cli/libs/diag"
|
2023-12-21 08:00:37 +00:00
|
|
|
"github.com/databricks/cli/libs/log"
|
2023-10-03 10:47:09 +00:00
|
|
|
"github.com/databricks/cli/libs/python"
|
2023-07-25 11:35:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type build struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func Build(name string) bundle.Mutator {
|
|
|
|
return &build{
|
|
|
|
name: name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *build) Name() string {
|
|
|
|
return fmt.Sprintf("artifacts.whl.Build(%s)", m.name)
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
func (m *build) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
2023-07-25 11:35:08 +00:00
|
|
|
artifact, ok := b.Config.Artifacts[m.name]
|
|
|
|
if !ok {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.Errorf("artifact doesn't exist: %s", m.name)
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
|
|
|
|
2023-11-29 10:40:12 +00:00
|
|
|
cmdio.LogString(ctx, fmt.Sprintf("Building %s...", m.name))
|
2023-07-25 11:35:08 +00:00
|
|
|
|
|
|
|
out, err := artifact.Build(ctx)
|
|
|
|
if err != nil {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.Errorf("build failed %s, error: %v, output: %s", m.name, err, out)
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
2023-12-21 08:00:37 +00:00
|
|
|
log.Infof(ctx, "Build succeeded")
|
2023-07-25 11:35:08 +00:00
|
|
|
|
2024-07-24 09:13:49 +00:00
|
|
|
dir := artifact.Path
|
|
|
|
distPath := filepath.Join(artifact.Path, "dist")
|
2023-07-25 11:35:08 +00:00
|
|
|
wheels := python.FindFilesWithSuffixInPath(distPath, ".whl")
|
|
|
|
if len(wheels) == 0 {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.Errorf("cannot find built wheel in %s for package %s", dir, m.name)
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
|
|
|
for _, wheel := range wheels {
|
|
|
|
artifact.Files = append(artifact.Files, config.ArtifactFile{
|
|
|
|
Source: wheel,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|