Skip to content

Commit

Permalink
Attach license to a Kitfile section where possible when generating
Browse files Browse the repository at this point in the history
Try to attach the detected license type to a Kitfile layer rather than
the overall package section -- i.e. if we have a model, assume the
license applies to the model, otherwise, stick it with a dataset or code
section. Fallback to package if nothing else makes sense.
  • Loading branch information
amisevsk committed Dec 12, 2024
1 parent 3f867b1 commit df6f11c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/lib/kitfile/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func GenerateKitfile(baseDir string, packageOpt *artifact.Package) (*artifact.Ki
// or datasets
var metadataPaths []string
var modelFiles []fs.DirEntry
var detectedLicenseType string
for _, d := range ds {
name := d.Name()
if d.IsDir() {
Expand Down Expand Up @@ -89,7 +90,7 @@ func GenerateKitfile(baseDir string, packageOpt *artifact.Package) (*artifact.Ki
output.Debugf("Error determining license type: %s", err)
output.Logf(output.LogLevelWarn, "Unable to determine license type")
}
kitfile.Package.License = licenseType
detectedLicenseType = licenseType
continue
}

Expand Down Expand Up @@ -141,6 +142,17 @@ func GenerateKitfile(baseDir string, packageOpt *artifact.Package) (*artifact.Ki
}
}

// If we detected a license, try to attach it to the Kitfile section that makes sense
if kitfile.Model != nil && detectedLicenseType != "" {
kitfile.Model.License = detectedLicenseType
} else if len(kitfile.DataSets) == 1 {
kitfile.DataSets[0].License = detectedLicenseType
} else if len(kitfile.Code) == 1 {
kitfile.Code[0].License = detectedLicenseType
} else {
kitfile.Package.License = detectedLicenseType
}

return kitfile, nil
}

Expand Down

0 comments on commit df6f11c

Please sign in to comment.