Skip to content
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

fall back to classifiers if [pypi] license text is really long #8690

Merged
merged 2 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/pypi/pypi-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getLicenses(packageData) {
const {
info: { license },
} = packageData
if (license) {
if (license && license.length < 40) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in #8689 (comment) we're going to have to make some kind of assumption here. The longest SPDX identifier in https://raw.githubusercontent.com/jslicense/spdx-license-ids/main/index.json is 36 characters so this seems like a reasonable-ish threshold.

My hunch is that the license meta-data field is more commonly used than the classifiers, so I think switching to prefer the classifiers in all cases is probably going to break more badges out in the wild than doing this.

There isn't really a perfect solution here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with the approach. I do think it might be worth adding an inline comment explaining this though so that 40 doesn't appear like a magic number to readers of the code.

I recognize that one could use git blame info to backtrack to this PR and explanation, but I'm a fan of having things be as self-explanatory as possible within the code

return [license]
} else {
const parenthesizedAcronymRegex = /\(([^)]+)\)/
Expand Down
7 changes: 7 additions & 0 deletions services/pypi/pypi-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ describe('PyPI helpers', function () {
classifiers: ['License :: OSI Approved :: MIT License'],
},
}),
given({
info: {
license:
'this text is really really really really really really long',
classifiers: ['License :: OSI Approved :: MIT License'],
},
}),
given({
info: {
license: '',
Expand Down