Skip to content

Commit

Permalink
feat(python): add license fields
Browse files Browse the repository at this point in the history
  • Loading branch information
afdesk committed May 16, 2023
1 parent ebd88ce commit ddd75b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/python/packaging/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"io"
"net/textproto"
"strings"

"golang.org/x/xerrors"

Expand All @@ -26,11 +27,26 @@ func (*Parser) Parse(r dio.ReadSeekerAt) ([]types.Library, []types.Dependency, e
return nil, nil, xerrors.Errorf("read MIME error: %w", err)
}

license := h.Get("License-Expression")
if license == "" {
license = h.Get("License")
}
if license == "" {
for _, classifier := range h.Values("Classifier") {
if strings.HasPrefix(classifier, "License ::") {
if values := strings.Split(classifier, " :: "); len(values) > 1 {
license = values[len(values)-1]
}
}
}
}

return []types.Library{
{
Name: h.Get("Name"),
Version: h.Get("Version"),
License: h.Get("License"),
Name: h.Get("Name"),
Version: h.Get("Version"),
License: license,
LicenseFile: h.Get(""),
},
}, nil, nil
}
1 change: 1 addition & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Library struct {
Version string
Indirect bool `json:",omitempty"`
License string `json:",omitempty"`
LicenseFile string `json:",omitempty"`
ExternalReferences []ExternalRef `json:",omitempty"`
Locations []Location `json:",omitempty"`
FilePath string `json:",omitempty"` // Required to show nested jars
Expand Down

0 comments on commit ddd75b5

Please sign in to comment.