Skip to content

Commit 5851f1f

Browse files
committed
Create a separate section for unknown licenses
Signed-off-by: akugarg <akanksha.garg2k@gmail.com>
1 parent c8cf696 commit 5851f1f

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/licensedcode/plugin_license.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ class LicenseScanner(ScanPlugin):
4141

4242
resource_attributes = dict([
4343
('licenses', attr.ib(default=attr.Factory(list))),
44+
('unknown_licenses', attr.ib(default=attr.Factory(list))),
4445
('license_expressions', attr.ib(default=attr.Factory(list))),
46+
('unknown_license_expressions', attr.ib(default=attr.Factory(list))),
47+
('spdx_license_expressions', attr.ib(default=attr.Factory(list))),
4548
('percentage_of_license_text', attr.ib(default=0)),
4649
])
4750

src/scancode/api.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ def get_licenses(location, min_score=0,
171171

172172
detected_licenses = []
173173
detected_expressions = []
174-
174+
unknown_expressions = []
175+
unknown_licenses=[]
175176
matches = idx.match(
176177
location=location, min_score=min_score, deadline=deadline, **kwargs)
177178

@@ -180,16 +181,23 @@ def get_licenses(location, min_score=0,
180181
for match in matches:
181182
qspans.append(match.qspan)
182183

183-
detected_expressions.append(match.rule.license_expression)
184-
185-
detected_licenses.extend(
186-
_licenses_data_from_match(
184+
if "unknown" in match.rule.license_expression: # TODO: use is_unknwon flag instead
185+
unknown_expressions.append(match.rule.license_expression)
186+
unknown_licenses.extend(_licenses_data_from_match(
187+
match=match,
188+
include_text=include_text,
189+
license_text_diagnostics=license_text_diagnostics,
190+
license_url_template=license_url_template))
191+
else:
192+
detected_expressions.append(match.rule.license_expression)
193+
detected_licenses.extend(
194+
_licenses_data_from_match(
187195
match=match,
188196
include_text=include_text,
189197
license_text_diagnostics=license_text_diagnostics,
190198
license_url_template=license_url_template)
191-
)
192-
199+
)
200+
193201
percentage_of_license_text = 0
194202
if match:
195203
# we need at least one match to compute a license_coverage
@@ -200,7 +208,9 @@ def get_licenses(location, min_score=0,
200208
detected_spdx_expressions = []
201209
return dict([
202210
('licenses', detected_licenses),
211+
('unknown_licenses', unknown_licenses),
203212
('license_expressions', detected_expressions),
213+
('unknown_license_expressions', unknown_expressions),
204214
('spdx_license_expressions', detected_spdx_expressions),
205215
('percentage_of_license_text', percentage_of_license_text),
206216
])

0 commit comments

Comments
 (0)