Skip to content

Commit b1c999f

Browse files
Rename detection_rules to detection_log
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent afd4025 commit b1c999f

File tree

795 files changed

+4967
-4967
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

795 files changed

+4967
-4967
lines changed

src/formattedcode/output_csv.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ def collect_keys(mapping, key_group):
146146

147147
for detection in scanned_file.get('license_detections', []):
148148
license_expression = detection["license_expression"]
149-
detection_rules = detection["detection_rules"]
150-
detection_rules = '\n'.join(detection_rules)
149+
detection_log = detection["detection_log"]
150+
detection_log = '\n'.join(detection_log)
151151
license_matches = detection["matches"]
152152
for match in license_matches:
153153
lic = dict(path=path)
154154
lic["license_expression"] = license_expression
155-
lic["detection_rules"] = detection_rules
155+
lic["detection_log"] = detection_log
156156

157157
for k, val in match.items():
158158
# do not include matched text for now.

src/licensedcode/detection.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def logger_debug(*args):
6666

6767

6868
MATCHER_UNDETECTED = '5-undetected'
69-
69+
7070
# All values of match_coverage less than this value and more than
7171
# `IMPERFECT_MATCH_COVERAGE_THR` are taken as `near-perfect-match-coverage` cases
7272
IMPERFECT_MATCH_COVERAGE_THR = 100
@@ -153,7 +153,7 @@ class LicenseDetection:
153153
'using the SPDX license expression syntax and ScanCode license keys.')
154154
)
155155

156-
detection_rules = attr.ib(
156+
detection_log = attr.ib(
157157
repr=False,
158158
default=attr.Factory(list),
159159
metadata=dict(
@@ -197,7 +197,7 @@ def from_matches(
197197
package_license=package_license
198198
)
199199

200-
reasons, license_expression = get_detected_license_expression(
200+
detection_log, license_expression = get_detected_license_expression(
201201
matches=matches,
202202
analysis=analysis,
203203
post_scan=post_scan,
@@ -209,7 +209,7 @@ def from_matches(
209209
return cls(
210210
matches=matches,
211211
license_expression=str(license_expression),
212-
detection_rules=reasons,
212+
detection_log=detection_log,
213213
)
214214

215215
def __eq__(self, other):
@@ -346,7 +346,7 @@ def append(
346346
"""
347347
Append the ``match`` LicenseMatch to this detection and update it
348348
accordingly.
349-
Append the ``reason`` to the detection_rules.
349+
Append the ``reason`` to the detection_log.
350350
351351
If ``combine_license`` is True the license_expression of the ``match``
352352
is combined with the detection license_expression. Do not combine
@@ -373,7 +373,7 @@ def append(
373373
self.matches.append(match)
374374
self.length += match.length
375375
if reason:
376-
self.detection_rules.append(reason)
376+
self.detection_log.append(reason)
377377

378378
licensing = get_cache().licensing
379379
if combine_license:
@@ -705,92 +705,92 @@ def has_unknown_references_to_local_files(license_matches):
705705

706706
def get_detected_license_expression(matches, analysis, post_scan=False):
707707
"""
708-
Return a tuple of (reasons, combined_expression) by combining a `matches` list of
708+
Return a tuple of (detection_log, combined_expression) by combining a `matches` list of
709709
LicenseMatch objects using an `analysis` code string.
710710
"""
711711
if TRACE or TRACE_ANALYSIS:
712712
logger_debug(f'license_matches {matches}', f'package_license {analysis}', f'post_scan: {post_scan}')
713713

714714
matches_for_expression = None
715715
combined_expression = None
716-
reasons = []
716+
detection_log = []
717717

718718
if analysis == DetectionCategory.FALSE_POSITVE.value:
719719
if TRACE_ANALYSIS:
720720
logger_debug(f'analysis {DetectionRule.FALSE_POSITIVE.value}')
721-
reasons.append(DetectionRule.FALSE_POSITIVE.value)
722-
return reasons, combined_expression
721+
detection_log.append(DetectionRule.FALSE_POSITIVE.value)
722+
return detection_log, combined_expression
723723

724724
elif analysis == DetectionCategory.UNDETECTED_LICENSE.value:
725725
if TRACE_ANALYSIS:
726726
logger_debug(f'analysis {DetectionCategory.UNDETECTED_LICENSE.value}')
727727
matches_for_expression = matches
728-
reasons.append(DetectionRule.UNDETECTED_LICENSE.value)
728+
detection_log.append(DetectionRule.UNDETECTED_LICENSE.value)
729729

730730
elif analysis == DetectionCategory.UNKNOWN_INTRO_BEFORE_DETECTION.value:
731731
if TRACE_ANALYSIS:
732732
logger_debug(f'analysis {DetectionCategory.UNKNOWN_INTRO_BEFORE_DETECTION.value}')
733733
matches_for_expression = filter_license_intros(matches)
734-
reasons.append(DetectionRule.UNKNOWN_INTRO_FOLLOWED_BY_MATCH.value)
734+
detection_log.append(DetectionRule.UNKNOWN_INTRO_FOLLOWED_BY_MATCH.value)
735735

736736
elif post_scan:
737737
if analysis == DetectionCategory.UNKNOWN_REFERENCE_IN_FILE_TO_PACKAGE.value:
738738
if TRACE_ANALYSIS:
739739
logger_debug(f'analysis {DetectionCategory.UNKNOWN_REFERENCE_IN_FILE_TO_PACKAGE.value}')
740740
matches_for_expression = filter_license_references(matches)
741-
reasons.append(DetectionRule.UNKNOWN_REFERENCE_IN_FILE_TO_PACKAGE.value)
741+
detection_log.append(DetectionRule.UNKNOWN_REFERENCE_IN_FILE_TO_PACKAGE.value)
742742

743743
elif analysis == DetectionCategory.UNKNOWN_REFERENCE_IN_FILE_TO_NONEXISTENT_PACKAGE.value:
744744
if TRACE_ANALYSIS:
745745
logger_debug(f'analysis {DetectionCategory.UNKNOWN_REFERENCE_IN_FILE_TO_NONEXISTENT_PACKAGE.value}')
746746
matches_for_expression = filter_license_references(matches)
747-
reasons.append(DetectionRule.UNKNOWN_REFERENCE_IN_FILE_TO_NONEXISTENT_PACKAGE.value)
747+
detection_log.append(DetectionRule.UNKNOWN_REFERENCE_IN_FILE_TO_NONEXISTENT_PACKAGE.value)
748748

749749
elif analysis == DetectionCategory.UNKNOWN_FILE_REFERENCE_LOCAL.value:
750750
if TRACE_ANALYSIS:
751751
logger_debug(f'analysis {DetectionCategory.UNKNOWN_FILE_REFERENCE_LOCAL.value}')
752752
matches_for_expression = filter_license_references(matches)
753-
reasons.append(DetectionRule.UNKNOWN_REFERENCE_TO_LOCAL_FILE.value)
753+
detection_log.append(DetectionRule.UNKNOWN_REFERENCE_TO_LOCAL_FILE.value)
754754

755755
elif analysis == DetectionCategory.PACKAGE_UNKNOWN_FILE_REFERENCE_LOCAL.value:
756756
if TRACE_ANALYSIS:
757757
logger_debug(f'analysis {DetectionCategory.PACKAGE_UNKNOWN_FILE_REFERENCE_LOCAL.value}')
758758
matches_for_expression = filter_license_references(matches)
759-
reasons.append(DetectionRule.PACKAGE_UNKNOWN_REFERENCE_TO_LOCAL_FILE.value)
759+
detection_log.append(DetectionRule.PACKAGE_UNKNOWN_REFERENCE_TO_LOCAL_FILE.value)
760760

761761
elif analysis == DetectionCategory.PACKAGE_ADD_FROM_SIBLING_FILE.value:
762762
if TRACE_ANALYSIS:
763763
logger_debug(f'analysis {DetectionCategory.PACKAGE_ADD_FROM_SIBLING_FILE.value}')
764764
matches_for_expression = filter_license_references(matches)
765-
reasons.append(DetectionRule.PACKAGE_ADD_FROM_SIBLING_FILE.value)
765+
detection_log.append(DetectionRule.PACKAGE_ADD_FROM_SIBLING_FILE.value)
766766

767767
elif analysis == DetectionCategory.PACKAGE_ADD_FROM_FILE.value:
768768
if TRACE_ANALYSIS:
769769
logger_debug(f'analysis {DetectionCategory.PACKAGE_ADD_FROM_FILE.value}')
770770
matches_for_expression = filter_license_references(matches)
771-
reasons.append(DetectionRule.PACKAGE_ADD_FROM_FILE.value)
771+
detection_log.append(DetectionRule.PACKAGE_ADD_FROM_FILE.value)
772772

773773
elif analysis == DetectionCategory.UNKNOWN_MATCH.value:
774774
if TRACE_ANALYSIS:
775775
logger_debug(f'analysis {DetectionCategory.UNKNOWN_MATCH.value}')
776776
matches_for_expression = matches
777-
reasons.append(DetectionRule.UNKNOWN_MATCH.value)
778-
return reasons, combined_expression
777+
detection_log.append(DetectionRule.UNKNOWN_MATCH.value)
778+
return detection_log, combined_expression
779779

780780
elif analysis == DetectionCategory.LICENSE_CLUES.value:
781781
if TRACE_ANALYSIS:
782782
logger_debug(f'analysis {DetectionCategory.LICENSE_CLUES.value}')
783-
reasons.append(DetectionRule.LICENSE_CLUES.value)
784-
return reasons, combined_expression
783+
detection_log.append(DetectionRule.LICENSE_CLUES.value)
784+
return detection_log, combined_expression
785785

786786
else:
787787
if TRACE_ANALYSIS:
788788
logger_debug(f'analysis {DetectionRule.NOT_COMBINED.value}')
789789
matches_for_expression = matches
790-
reasons.append(DetectionRule.NOT_COMBINED.value)
790+
detection_log.append(DetectionRule.NOT_COMBINED.value)
791791

792792
if TRACE:
793-
logger_debug(f'matches_for_expression: {matches_for_expression}', f'reasons: {reasons}')
793+
logger_debug(f'matches_for_expression: {matches_for_expression}', f'detection_log: {detection_log}')
794794

795795
if isinstance(matches[0], dict):
796796
combined_expression = combine_expressions(
@@ -804,7 +804,7 @@ def get_detected_license_expression(matches, analysis, post_scan=False):
804804
if TRACE or TRACE_ANALYSIS:
805805
logger_debug(f'combined_expression {combined_expression}')
806806

807-
return reasons, combined_expression
807+
return detection_log, combined_expression
808808

809809

810810
def get_unknown_license_detection(query_string):

src/licensedcode/plugin_license.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ def add_referenced_license_matches_for_detections(resource, codebase):
252252
if not detection_modified:
253253
continue
254254

255-
reasons, license_expression = get_detected_license_expression(
255+
detection_log, license_expression = get_detected_license_expression(
256256
matches=matches,
257257
analysis=DetectionCategory.UNKNOWN_FILE_REFERENCE_LOCAL.value,
258258
post_scan=True,
259259
)
260260
detection["license_expression"] = str(license_expression)
261-
detection["detection_rules"] = reasons
261+
detection["detection_log"] = detection_log
262262

263263
if modified:
264264
license_expressions = [

src/licensedcode/plugin_licenses_reference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def get_license_detection_references(license_detections_by_path):
228228
Get LicenseDetection data for references from a mapping of path:[LicenseDetection],
229229
i.e. path and a list of LicenseDetection at that path.
230230
231-
Also removes `matches` and `detection_rules` from each LicenseDetection mapping
231+
Also removes `matches` and `detection_log` from each LicenseDetection mapping
232232
and only keeps a LicenseExpression string and an computed identifier per detection,
233233
as this LicenseDetection data is referenced at top-level by the identifier.
234234
"""
@@ -239,7 +239,7 @@ def get_license_detection_references(license_detections_by_path):
239239
for detection in detections:
240240
detection_obj = LicenseDetection(**detection)
241241
_matches = detection.pop('matches')
242-
_reasons = detection.pop('detection_rules')
242+
_detection_log = detection.pop('detection_log')
243243
detection_obj.file_region = detection_obj.get_file_region(path=path)
244244
detection["id"] = detection_obj.identifier
245245

src/packagedcode/licensing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ def add_referenced_license_matches_for_package(resource, codebase, no_licenses):
114114
if not detection_modified:
115115
continue
116116

117-
reasons, license_expression = get_detected_license_expression(
117+
detection_log, license_expression = get_detected_license_expression(
118118
matches=matches,
119119
analysis=DetectionCategory.PACKAGE_UNKNOWN_FILE_REFERENCE_LOCAL.value,
120120
post_scan=True,
121121
)
122122
detection["license_expression"] = str(license_expression)
123-
detection["detection_rules"] = reasons
123+
detection["detection_log"] = detection_log
124124

125125
if modified:
126126
license_expressions = [
@@ -211,18 +211,18 @@ def add_referenced_license_detection_from_package(resource, codebase, no_license
211211
modified = True
212212
detection_modified = True
213213
matches.extend(pkg_detection["matches"])
214-
analysis=DetectionCategory.UNKNOWN_REFERENCE_IN_FILE_TO_PACKAGE.value
214+
analysis = DetectionCategory.UNKNOWN_REFERENCE_IN_FILE_TO_PACKAGE.value
215215

216216
if not detection_modified:
217217
continue
218218

219-
reasons, license_expression = get_detected_license_expression(
219+
detection_log, license_expression = get_detected_license_expression(
220220
matches=matches,
221221
analysis=analysis,
222222
post_scan=True,
223223
)
224224
detection["license_expression"] = str(license_expression)
225-
detection["detection_rules"] = reasons
225+
detection["detection_log"] = detection_log
226226

227227
if modified:
228228

src/packagedcode/plugin_package.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ def add_license_from_file(resource, codebase, no_licenses):
238238
pkg["license_detections"] = license_detections_file.copy()
239239
for detection in pkg["license_detections"]:
240240

241-
if detection["detection_rules"] == [DetectionRule.NOT_COMBINED.value]:
242-
detection["detection_rules"] = [DetectionRule.PACKAGE_ADD_FROM_FILE.value]
241+
if detection["detection_log"] == [DetectionRule.NOT_COMBINED.value]:
242+
detection["detection_log"] = [DetectionRule.PACKAGE_ADD_FROM_FILE.value]
243243
else:
244-
detection["detection_rules"].append(DetectionRule.PACKAGE_ADD_FROM_FILE.value)
244+
detection["detection_log"].append(DetectionRule.PACKAGE_ADD_FROM_FILE.value)
245245

246246
license_expression = get_license_expression_from_detection_mappings(
247247
detections=license_detections_file,

tests/cluecode/data/plugin_filter_clues/filtered-expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"license_detections": [
2525
{
2626
"license_expression": "apache-1.1",
27-
"detection_rules": [
27+
"detection_log": [
2828
"not-combined"
2929
],
3030
"matches": [

tests/cluecode/data/plugin_filter_clues/filtered-expected2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"license_detections": [
2525
{
2626
"license_expression": "pygres-2.2",
27-
"detection_rules": [
27+
"detection_log": [
2828
"not-combined"
2929
],
3030
"matches": [

tests/cluecode/data/plugin_filter_clues/filtered-expected3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"license_detections": [
2525
{
2626
"license_expression": "pcre",
27-
"detection_rules": [
27+
"detection_log": [
2828
"not-combined"
2929
],
3030
"matches": [

0 commit comments

Comments
 (0)