@@ -45,7 +45,7 @@ def logger_debug(*args):
4545
4646logger = logging .getLogger (__name__ )
4747
48- if TRACE :
48+ if TRACE or TRACE_REFERENCE :
4949 import sys
5050 logging .basicConfig (stream = sys .stdout )
5151 logger .setLevel (logging .DEBUG )
@@ -217,6 +217,8 @@ def process_codebase(self, codebase, license_text=False, license_diagnostics=Fal
217217 f'before: { license_expressions_before } \n '
218218 f'after : { license_expressions_after } '
219219 )
220+
221+ #raise Exception()
220222
221223 license_detections = collect_license_detections (
222224 codebase = codebase ,
@@ -273,8 +275,6 @@ def add_referenced_filenames_license_matches_for_detections(resource, codebase):
273275 license_detection_mapping = license_detection_mapping ,
274276 file_path = resource .path ,
275277 )
276- detection_modified = False
277- detections_added = []
278278 license_match_mappings = license_detection_mapping ["matches" ]
279279 referenced_filenames = get_referenced_filenames (license_detection .matches )
280280
@@ -285,6 +285,7 @@ def add_referenced_filenames_license_matches_for_detections(resource, codebase):
285285 )
286286 continue
287287
288+ referenced_detections = []
288289 for referenced_filename in referenced_filenames :
289290 referenced_resource = find_referenced_resource (
290291 referenced_filename = referenced_filename ,
@@ -293,46 +294,47 @@ def add_referenced_filenames_license_matches_for_detections(resource, codebase):
293294 )
294295
295296 if referenced_resource and referenced_resource .license_detections :
296- referenced_license_expression = combine_expressions (
297- expressions = [
298- detection ["license_expression" ]
299- for detection in referenced_resource .license_detections
300- ],
297+ referenced_detections .extend (
298+ referenced_resource .license_detections
301299 )
302- if not use_referenced_license_expression (
303- referenced_license_expression = referenced_license_expression ,
304- license_detection = license_detection ,
305- ):
306- if TRACE_REFERENCE :
307- logger_debug (
308- f'use_referenced_license_expression: False for '
309- f'resource: { referenced_resource .path } and '
310- f'license_expression: { referenced_license_expression } ' ,
311- )
312- continue
313-
314- if TRACE_REFERENCE :
315- logger_debug (
316- f'use_referenced_license_expression: True for '
317- f'resource: { referenced_resource .path } and '
318- f'license_expression: { referenced_license_expression } ' ,
300+
301+ for detection in referenced_resource .license_detections :
302+ populate_matches_with_path (
303+ matches = detection ["matches" ],
304+ path = referenced_resource .path
319305 )
320306
321- modified = True
322- detection_modified = True
323- detections_added .extend (referenced_resource .license_detections )
324- matches_to_extend = get_matches_from_detection_mappings (
325- license_detections = referenced_resource .license_detections
326- )
327- populate_matches_with_path (
328- matches = matches_to_extend ,
329- path = referenced_resource .path
307+ referenced_license_expression = combine_expressions (
308+ expressions = [
309+ detection ["license_expression" ]
310+ for detection in referenced_detections
311+ ],
312+ )
313+ if not use_referenced_license_expression (
314+ referenced_license_expression = referenced_license_expression ,
315+ license_detection = license_detection ,
316+ ):
317+ if TRACE_REFERENCE :
318+ logger_debug (
319+ f'use_referenced_license_expression: False for '
320+ f'resource: { referenced_resource .path } and '
321+ f'license_expression: { referenced_license_expression } ' ,
330322 )
331- license_match_mappings .extend (matches_to_extend )
332-
333- if not detection_modified :
334323 continue
335324
325+ if TRACE_REFERENCE :
326+ logger_debug (
327+ f'use_referenced_license_expression: True for '
328+ f'resource: { referenced_resource .path } and '
329+ f'license_expression: { referenced_license_expression } ' ,
330+ )
331+
332+ modified = True
333+ matches_to_extend = get_matches_from_detection_mappings (
334+ license_detections = referenced_detections
335+ )
336+ license_match_mappings .extend (matches_to_extend )
337+
336338 detection_log , license_expression = get_detected_license_expression (
337339 license_match_mappings = license_match_mappings ,
338340 analysis = DetectionCategory .UNKNOWN_FILE_REFERENCE_LOCAL .value ,
@@ -348,7 +350,7 @@ def add_referenced_filenames_license_matches_for_detections(resource, codebase):
348350 license_detection_mapping ["detection_log" ] = detection_log
349351 license_detection_mapping ["identifier" ] = get_new_identifier_from_detections (
350352 initial_detection = license_detection_mapping ,
351- detections_added = detections_added ,
353+ detections_added = referenced_detections ,
352354 license_expression = license_expression ,
353355 )
354356
0 commit comments