@@ -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,45 @@ 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 } ' ,
319- )
320-
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
330- )
331- license_match_mappings .extend (matches_to_extend )
332300
333- if not detection_modified :
301+ referenced_license_expression = combine_expressions (
302+ expressions = [
303+ detection ["license_expression" ]
304+ for detection in referenced_detections
305+ ],
306+ )
307+ if not use_referenced_license_expression (
308+ referenced_license_expression = referenced_license_expression ,
309+ license_detection = license_detection ,
310+ ):
311+ if TRACE_REFERENCE :
312+ logger_debug (
313+ f'use_referenced_license_expression: False for '
314+ f'resource: { referenced_resource .path } and '
315+ f'license_expression: { referenced_license_expression } ' ,
316+ )
334317 continue
335318
319+ if TRACE_REFERENCE :
320+ logger_debug (
321+ f'use_referenced_license_expression: True for '
322+ f'resource: { referenced_resource .path } and '
323+ f'license_expression: { referenced_license_expression } ' ,
324+ )
325+
326+ modified = True
327+ matches_to_extend = get_matches_from_detection_mappings (
328+ license_detections = referenced_detections
329+ )
330+ populate_matches_with_path (
331+ matches = matches_to_extend ,
332+ path = referenced_resource .path
333+ )
334+ license_match_mappings .extend (matches_to_extend )
335+
336336 detection_log , license_expression = get_detected_license_expression (
337337 license_match_mappings = license_match_mappings ,
338338 analysis = DetectionCategory .UNKNOWN_FILE_REFERENCE_LOCAL .value ,
@@ -348,7 +348,7 @@ def add_referenced_filenames_license_matches_for_detections(resource, codebase):
348348 license_detection_mapping ["detection_log" ] = detection_log
349349 license_detection_mapping ["identifier" ] = get_new_identifier_from_detections (
350350 initial_detection = license_detection_mapping ,
351- detections_added = detections_added ,
351+ detections_added = referenced_detections ,
352352 license_expression = license_expression ,
353353 )
354354
0 commit comments