Skip to content

Commit 504434b

Browse files
Only show detection logs on diagnostics option
Only show license detection logs when --license-text-diagnostics is enabled. Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent 69ccacc commit 504434b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/licensedcode/detection.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ def dict_fields(attr, value):
425425
if attr.name == 'file_region':
426426
return False
427427

428+
if attr.name == 'detection_log' and not license_text_diagnostics:
429+
return False
430+
428431
return True
429432

430433
data_matches = []
@@ -470,7 +473,7 @@ def from_license_detection_mapping(
470473

471474
detection = cls(
472475
license_expression=license_detection_mapping["license_expression"],
473-
detection_log=license_detection_mapping["detection_log"],
476+
detection_log=license_detection_mapping.get("detection_log", []) or None,
474477
matches=matches,
475478
file_region=None,
476479
)
@@ -589,7 +592,7 @@ class UniqueDetection:
589592
files = attr.ib(factory=list)
590593

591594
@classmethod
592-
def get_unique_detections(cls, license_detections):
595+
def get_unique_detections(cls, license_detections, license_text_diagnostics):
593596
"""
594597
Return all unique UniqueDetection from a ``license_detections`` list of
595598
LicenseDetection.
@@ -609,7 +612,7 @@ def get_unique_detections(cls, license_detections):
609612
cls(
610613
identifier=detection.identifier_with_expression,
611614
license_expression=detection_mapping["license_expression"],
612-
detection_log=detection_mapping["detection_log"],
615+
detection_log=detection_mapping.get("detection_log", []) or [],
613616
matches=detection_mapping["matches"],
614617
detection_count=len(file_regions),
615618
files=file_regions,
@@ -618,12 +621,16 @@ def get_unique_detections(cls, license_detections):
618621

619622
return unique_license_detections
620623

621-
def to_dict(self):
624+
def to_dict(self, license_text_diagnostics):
622625

623626
def dict_fields(attr, value):
627+
624628
if attr.name == 'files':
625629
return False
626630

631+
if attr.name == 'detection_log' and not license_text_diagnostics:
632+
return False
633+
627634
return True
628635

629636
return attr.asdict(self, filter=dict_fields)

src/licensedcode/plugin_license.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def get_scanner(
151151
unknown_licenses=unknown_licenses,
152152
)
153153

154-
def process_codebase(self, codebase, **kwargs):
154+
def process_codebase(self, codebase, license_text_diagnostics, **kwargs):
155155
"""
156156
Post-process ``codebase`` to follow referenced filenames to license
157157
matches in other files.
@@ -180,7 +180,10 @@ def process_codebase(self, codebase, **kwargs):
180180
return
181181

182182
license_detections = collect_license_detections(codebase)
183-
unique_license_detections = UniqueDetection.get_unique_detections(license_detections)
183+
unique_license_detections = UniqueDetection.get_unique_detections(
184+
license_detections=license_detections,
185+
license_text_diagnostics=license_text_diagnostics,
186+
)
184187

185188
if TRACE:
186189
logger_debug(
@@ -211,7 +214,7 @@ def process_codebase(self, codebase, **kwargs):
211214
detections=unique_license_detections,
212215
)
213216
codebase.attributes.license_detections.extend([
214-
unique_detection.to_dict()
217+
unique_detection.to_dict(license_text_diagnostics=license_text_diagnostics)
215218
for unique_detection in unique_license_detections
216219
])
217220

0 commit comments

Comments
 (0)