-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(python): add license fields #217
Conversation
pkg/python/packaging/parse.go
Outdated
license := h.Get("License-Expression") | ||
if license == "" { | ||
license = h.Get("License") | ||
} | ||
if license == "" { | ||
for _, classifier := range h.Values("Classifier") { | ||
if strings.HasPrefix(classifier, "License :: ") { | ||
values := strings.Split(classifier, " :: ") | ||
license = values[len(values)-1] | ||
break | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to flatten the conditions.
license := h.Get("License-Expression") | |
if license == "" { | |
license = h.Get("License") | |
} | |
if license == "" { | |
for _, classifier := range h.Values("Classifier") { | |
if strings.HasPrefix(classifier, "License :: ") { | |
values := strings.Split(classifier, " :: ") | |
license = values[len(values)-1] | |
break | |
} | |
} | |
} | |
// "License-Expression" takes precedence as "License" is deprecated. | |
// cf. https://peps.python.org/pep-0639/#deprecate-license-field | |
var license string | |
if l := h.Get("License-Expression"); l != "" { | |
license = l | |
else if l := h.Get("License"); l != "" { | |
license = l | |
else { | |
for _, classifier := range h.Values("Classifier") { | |
if strings.HasPrefix(classifier, "License :: ") { | |
values := strings.Split(classifier, " :: ") | |
license = values[len(values)-1] | |
break | |
} | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, sure
pkg/python/packaging/parse.go
Outdated
Name: h.Get("Name"), | ||
Version: h.Get("Version"), | ||
License: license, | ||
LicenseFile: h.Get("License-File"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be a bit hacky, but I'm not keen on adding a new field only for python. What if adding file://license.txt
to License
if the license is empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's try this way.
@knqyf263 could you take a look at this PR again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
feat(python): add license fields (aquasecurity#217)
License
field is deprecated and replaced by the newLicense-Expression
field, and there was addedLicense-File
field.Read more here PEP 639 – Improving License Clarity with Better Package .
also there are legacy packages that use license classifiers (
Classifier
field), so we have to check it too.