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

refactor: parameter license_classifier expects a list #133

Merged
merged 1 commit into from
Oct 31, 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
12 changes: 4 additions & 8 deletions piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,9 @@ def get_pkg_info(pkg):
for key in METADATA_KEYS:
pkg_info[key] = metadata.get(key, LICENSE_UNKNOWN)

classifiers = metadata.get_all("classifier")
if classifiers:
pkg_info['license_classifier'] = \
find_license_from_classifier(classifiers)
classifiers = metadata.get_all("classifier", [])
pkg_info['license_classifier'] = \
find_license_from_classifier(classifiers)
Comment on lines -169 to +171
Copy link
Owner

Choose a reason for hiding this comment

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

I have checked API Reference of importlib_metadata.

It's a simple and beautiful solution 👍


if args.filter_strings:
for k in pkg_info:
Expand Down Expand Up @@ -437,13 +436,10 @@ def find_license_from_classifier(classifiers):


def select_license_by_source(from_source, license_classifier, license_meta):
if isinstance(license_classifier, str):
license_classifier = [license_classifier]
license_classifier_set = set(license_classifier) or {LICENSE_UNKNOWN}
if (from_source == FromArg.CLASSIFIER or
from_source == FromArg.MIXED and
len(license_classifier) > 0 and
LICENSE_UNKNOWN not in license_classifier):
len(license_classifier) > 0):
return license_classifier_set
else:
return {license_meta}
Expand Down
2 changes: 1 addition & 1 deletion test_piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def test_select_license_by_source(self):
'MIT'))
self.assertEqual({'Apache License 2.0'},
select_license_by_source(FromArg.MIXED,
'Apache License 2.0',
['Apache License 2.0'],
'Apache-2.0'))

def test_with_system(self):
Expand Down