2023-07-26 10:07:26 +00:00
|
|
|
package artifacts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/artifacts/whl"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
var inferMutators map[config.ArtifactType]mutatorFactory = map[config.ArtifactType]mutatorFactory{
|
|
|
|
config.ArtifactPythonWheel: whl.InferBuildCommand,
|
|
|
|
}
|
|
|
|
|
|
|
|
func getInferMutator(t config.ArtifactType, name string) bundle.Mutator {
|
|
|
|
mutatorFactory, ok := inferMutators[t]
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return mutatorFactory(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func InferMissingProperties() bundle.Mutator {
|
|
|
|
return &all{
|
|
|
|
name: "infer",
|
|
|
|
fn: inferArtifactByName,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func inferArtifactByName(name string) (bundle.Mutator, error) {
|
|
|
|
return &infer{name}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type infer struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *infer) Name() string {
|
|
|
|
return fmt.Sprintf("artifacts.Infer(%s)", m.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *infer) Apply(ctx context.Context, b *bundle.Bundle) error {
|
|
|
|
artifact, ok := b.Config.Artifacts[m.name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("artifact doesn't exist: %s", m.name)
|
|
|
|
}
|
|
|
|
|
2023-08-28 16:29:04 +00:00
|
|
|
// only try to infer command if it's not already defined
|
|
|
|
// and there is no explicitly files defined which means
|
|
|
|
// that the package is built outside of bundle cycles
|
|
|
|
// manually by customer
|
|
|
|
if artifact.BuildCommand != "" || len(artifact.Files) > 0 {
|
2023-07-26 10:07:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
inferMutator := getInferMutator(artifact.Type, m.name)
|
|
|
|
if inferMutator != nil {
|
|
|
|
return bundle.Apply(ctx, b, inferMutator)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|