Skip to content

Commit

Permalink
Prefer License-Expression with --from=mixed
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Oct 30, 2024
1 parent a1f054f commit 84b2837
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 4 additions & 7 deletions piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,21 +625,18 @@ def select_license_by_source(
license_meta: str,
license_expression: str,
) -> set[str]:
if license_expression != LICENSE_UNKNOWN:
return {license_expression}

license_classifier_set = set(license_classifier) or {LICENSE_UNKNOWN}
if (
from_source == FromArg.CLASSIFIER
or from_source == FromArg.MIXED
and len(license_classifier) > 0
):
return license_classifier_set
elif (
from_source == FromArg.META
or from_source == FromArg.MIXED
and license_meta != LICENSE_UNKNOWN
):
return {license_meta}
else:
return {license_expression}
return {license_meta}


def get_output_fields(args: CustomNamespace) -> list[str]:
Expand Down
9 changes: 9 additions & 0 deletions test_piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,15 @@ def test_select_license_by_source(self) -> None:
FromArg.MIXED, [], LICENSE_UNKNOWN, "MIT"
),
)
self.assertEqual(
{"Apache-2.0"},
select_license_by_source(
FromArg.MIXED,
["Apache License 2.0"],
"Apache",
"Apache-2.0",
),
)
self.assertEqual(
{"Apache-2.0"},
select_license_by_source(
Expand Down

0 comments on commit 84b2837

Please sign in to comment.