Skip to content

Commit

Permalink
update license matching
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Apr 9, 2020
1 parent 2721a91 commit e755850
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions grayskull/license/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ def match_license(name: str) -> dict:
spdx_license = best_matches[0]
if spdx_license[1] != 100:
best_matches = [l[0] for l in best_matches if not l[0].endswith("-only")]

if best_matches:
spdx_license = process.extractOne(
name, best_matches, scorer=token_sort_ratio
)
best_matches = process.extract(name, best_matches, scorer=token_set_ratio)
spdx_license = best_matches[0]
best_matches = [l[0] for l in best_matches if l[1] >= spdx_license[1]]
if len(best_matches) > 1:
spdx_license = process.extractOne(
name, best_matches, scorer=token_sort_ratio
)

log.info(
f"Best match for license {name} was {spdx_license}.\n"
f"Best matches: {best_matches}"
Expand Down Expand Up @@ -325,8 +331,9 @@ def get_license_type(path_license: str, default: Optional[str] = None) -> Option
if default and best_match[0][1] < 51:
log.info(f"Match too low for recipe {best_match}, using the default {default}")
return default

higher_match = best_match[0]
equal_values = [val[0] for val in best_match if higher_match[1] == val[1]]
equal_values = [val[0] for val in best_match if val[1] > (higher_match[1] - 3)]
if len(equal_values) > 1:
higher_match = process.extractOne(
license_content, equal_values, scorer=token_set_ratio
Expand Down

0 comments on commit e755850

Please sign in to comment.