Skip to content

Commit

Permalink
Parse Python licenses from LicenseExpression entry in the Wheel Metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Colm O hEigeartaigh <coheigea@apache.org>
  • Loading branch information
coheigea committed Dec 14, 2023
1 parent 09e62c3 commit ac85fdf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion syft/pkg/cataloger/python/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func newPackageForRequirementsWithMetadata(name, version string, metadata pkg.Py

func newPackageForPackage(resolver file.Resolver, m parsedData, sources ...file.Location) pkg.Package {
var licenseSet pkg.LicenseSet
if m.Licenses != "" {
if m.LicenseExpression != "" {

Check failure on line 62 in syft/pkg/cataloger/python/package.go

View workflow job for this annotation

GitHub Actions / Static analysis

ifElseChain: rewrite if-else to switch statement (gocritic)
licenseSet = pkg.NewLicenseSet(pkg.NewLicensesFromLocation(m.LicenseLocation, m.LicenseExpression)...)
} else if m.Licenses != "" {
licenseSet = pkg.NewLicenseSet(pkg.NewLicensesFromLocation(m.LicenseLocation, m.Licenses)...)
} else if m.LicenseLocation.Path() != "" {
// If we have a license file then resolve and parse it
Expand Down
3 changes: 2 additions & 1 deletion syft/pkg/cataloger/python/parse_wheel_egg_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type parsedData struct {
Licenses string `mapstructure:"License"`
LicenseFile string `mapstructure:"LicenseFile"`
LicenseExpression string `mapstructure:"LicenseExpression"`
LicenseLocation file.Location
pkg.PythonPackage `mapstructure:",squash"`
}
Expand Down Expand Up @@ -81,7 +82,7 @@ func parseWheelOrEggMetadata(path string, reader io.Reader) (parsedData, error)
// add additional metadata not stored in the egg/wheel metadata file

pd.SitePackagesRootPath = determineSitePackagesRootPath(path)
if pd.Licenses != "" {
if pd.Licenses != "" || pd.LicenseExpression != "" {
pd.LicenseLocation = file.NewLocation(path)
} else if pd.LicenseFile != "" {
pd.LicenseLocation = file.NewLocation(filepath.Join(filepath.Dir(path), pd.LicenseFile))
Expand Down

0 comments on commit ac85fdf

Please sign in to comment.