1616from plugincode .post_scan import post_scan_impl
1717
1818from packagedcode .utils import combine_expressions
19+ from licensedcode .detection import get_matches_from_detections
1920
2021# Tracing flags
2122TRACE = False
@@ -124,11 +125,12 @@ def compute_license_score(codebase):
124125 """
125126
126127 scoring_elements = ScoringElements ()
127- declared_licenses = get_field_values_from_codebase_resources (
128+ license_detections = get_field_values_from_codebase_resources (
128129 codebase = codebase ,
129130 field_name = 'licenses' ,
130131 key_files_only = True ,
131132 )
133+ declared_licenses = get_matches_from_detections (license_detections )
132134 declared_license_expressions = get_field_values_from_codebase_resources (
133135 codebase = codebase , field_name = 'license_expressions' , key_files_only = True
134136 )
@@ -140,9 +142,10 @@ def compute_license_score(codebase):
140142 codebase = codebase , field_name = 'copyrights' , key_files_only = True
141143 )
142144
143- other_licenses = get_field_values_from_codebase_resources (
145+ other_license_detections = get_field_values_from_codebase_resources (
144146 codebase = codebase , field_name = 'licenses' , key_files_only = False
145147 )
148+ other_licenses = get_matches_from_detections (other_license_detections )
146149
147150 scoring_elements .declared_license = bool (declared_licenses )
148151 if scoring_elements .declared_license :
@@ -244,20 +247,19 @@ class LicenseFilter(object):
244247
245248def is_good_license (detected_license ):
246249 """
247- Return True if a `detected license` mapping is consider to a high quality
250+ Return True if a `detected license` mapping is considered to be a high quality
248251 conclusive match.
249252 """
250253 score = detected_license ['score' ]
251- rule = detected_license ['matched_rule' ]
252- coverage = rule .get ('match_coverage' ) or 0
253- relevance = rule .get ('rule_relevance' ) or 0
254+ coverage = detected_license .get ('match_coverage' ) or 0
255+ relevance = detected_license .get ('rule_relevance' ) or 0
254256 match_types = dict (
255257 [
256- ('is_license_text' , rule ['is_license_text' ]),
257- ('is_license_notice' , rule ['is_license_notice' ]),
258- ('is_license_reference' , rule ['is_license_reference' ]),
259- ('is_license_tag' , rule ['is_license_tag' ]),
260- ('is_license_intro' , rule ['is_license_intro' ]),
258+ ('is_license_text' , detected_license ['is_license_text' ]),
259+ ('is_license_notice' , detected_license ['is_license_notice' ]),
260+ ('is_license_reference' , detected_license ['is_license_reference' ]),
261+ ('is_license_tag' , detected_license ['is_license_tag' ]),
262+ ('is_license_intro' , detected_license ['is_license_intro' ]),
261263 ]
262264 )
263265 matched = False
@@ -320,15 +322,24 @@ def get_field_values_from_codebase_resources(codebase, field_name, key_files_onl
320322 return values
321323
322324
323- def get_license_categories (license_infos ):
325+ def get_categories_from_match (license_match ):
326+ """
327+ Return a list of license category strings from a single LicenseMatch mapping.
328+ """
329+ licenses = license_match .get ('licenses' )
330+ return [license_info .get ('category' ) for license_info in licenses ]
331+
332+
333+ def get_license_categories (declared_licenses ):
324334 """
325335 Return a list of license category strings from `license_infos`
326336 """
327337 license_categories = []
328- for license_info in license_infos :
329- category = license_info .get ('category' , '' )
330- if category not in license_categories :
331- license_categories .append (category )
338+
339+ for match in declared_licenses :
340+ for category in get_categories_from_match (match ):
341+ if category not in license_categories :
342+ license_categories .append (category )
332343 return license_categories
333344
334345
@@ -339,11 +350,10 @@ def check_for_license_texts(declared_licenses):
339350 If so, return True. Otherwise, return False.
340351 """
341352 for declared_license in declared_licenses :
342- matched_rule = declared_license .get ('matched_rule' , {})
343353 if any (
344354 [
345- matched_rule .get ('is_license_text' , False ),
346- matched_rule .get ('is_license_notice' , False ),
355+ declared_license .get ('is_license_text' , False ),
356+ declared_license .get ('is_license_notice' , False ),
347357 ]
348358 ):
349359 return True
@@ -379,9 +389,10 @@ def check_for_conflicting_licenses(other_licenses):
379389
380390 If so, return True. Otherwise, return False.
381391 """
382- for license_info in other_licenses :
383- if license_info .get ('category' , '' ) in CONFLICTING_LICENSE_CATEGORIES :
384- return True
392+ for license_match in other_licenses :
393+ for category in get_categories_from_match (license_match ):
394+ if category in CONFLICTING_LICENSE_CATEGORIES :
395+ return True
385396 return False
386397
387398
0 commit comments