Skip to content

Commit ffdec4e

Browse files
Modify processing None at license_expressions
Modify get_license_expression to not pass None values to combine_expression, and also handle if all license detections are None, by getting a expression from the license_matches, or raising an Error if no license_matches. See - aboutcode-org/scancode.io#219 Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 935be1a commit ffdec4e

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

src/packagedcode/debian_copyright.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ def get_license_expression(
170170
return ['unknown']
171171

172172
detected_expressions = [match.rule.license_expression for match in matches]
173-
expression = combine_expressions(detected_expressions, unique=filter_licenses)
173+
license_expression = combine_expressions(detected_expressions, unique=filter_licenses)
174174

175175
if simplify_licenses:
176-
return dedup_expression(expression=expression)
176+
return dedup_expression(license_expression=license_expression)
177177
else:
178-
return expression
178+
return license_expression
179179

180180
def get_copyright(self, *args, **kwargs):
181181
return '\n'.join(self.detected_copyrights)
@@ -238,7 +238,7 @@ def get_primary_license(self):
238238
)
239239
]
240240

241-
self.primary_license = dedup_expression(expression=str(combine_expressions(expressions)))
241+
self.primary_license = dedup_expression(license_expression=str(combine_expressions(expressions)))
242242

243243
def get_declared_license(
244244
self, filter_licenses=False, skip_debian_packaging=False, *args, **kwargs
@@ -355,13 +355,23 @@ def get_license_expression(
355355
expressions = [
356356
license_detection.license_expression_object
357357
for license_detection in license_detections
358+
if license_detection.license_expression_object != None
358359
]
359360

360-
expression = str(combine_expressions(expressions, unique=False))
361+
if expressions:
362+
license_expression = str(combine_expressions(expressions, unique=False))
363+
else:
364+
license_matches = list(self.license_matches)
365+
if license_matches:
366+
license_expression = get_license_expression_from_matches(license_matches)
367+
else:
368+
msg = f'Debian Copyright file does not have any licenses detected in it. Location: {self.location}'
369+
raise NoLicenseFoundError(msg)
370+
361371
if simplify_licenses:
362-
return dedup_expression(expression=expression)
372+
return dedup_expression(license_expression=license_expression)
363373
else:
364-
return expression
374+
return license_expression
365375

366376
@staticmethod
367377
def filter_duplicate_declared_license(paragraphs):
@@ -1030,8 +1040,8 @@ def get_license_matches(location=None, query_string=None):
10301040
return idx.match(location=location, query_string=query_string)
10311041

10321042

1033-
def dedup_expression(expression, licensing=Licensing()):
1034-
return str(licensing.dedup(expression))
1043+
def dedup_expression(license_expression, licensing=Licensing()):
1044+
return str(licensing.dedup(license_expression))
10351045

10361046

10371047
def clean_debian_comma_logic(exp):

0 commit comments

Comments
 (0)