Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug at following package license references #3970

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/licensedcode/plugin_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ def add_referenced_filenames_license_matches_for_detections(resource, codebase):
path=referenced_resource.path
)

if not referenced_detections:
continue

referenced_license_expression = combine_expressions(
expressions=[
detection["license_expression"]
Expand All @@ -314,15 +317,15 @@ def add_referenced_filenames_license_matches_for_detections(resource, codebase):
referenced_license_expression=referenced_license_expression,
license_detection=license_detection,
):
if TRACE_REFERENCE:
if TRACE_REFERENCE and referenced_resource:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

referenced_resource is declared in another scope, which may be a problem. You may want to track referenced_resources_with_detections as a list of Resource rather than referenced_detections so you can:

  1. debug trace as needed
  2. account for when you have more than one file referenced.

logger_debug(
f'use_referenced_license_expression: False for '
f'resource: {referenced_resource.path} and '
f'license_expression: {referenced_license_expression}',
)
continue

if TRACE_REFERENCE:
if TRACE_REFERENCE and referenced_resource:
logger_debug(
f'use_referenced_license_expression: True for '
f'resource: {referenced_resource.path} and '
Expand Down
3 changes: 3 additions & 0 deletions src/packagedcode/licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ def add_referenced_license_matches_for_package(resource, codebase):
):
continue

if not (referenced_resource and referenced_resource.license_detections):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, referenced_resource is referenced below outside of this loop and may not exists at all.

continue

modified = True
detections_added.extend(referenced_resource.license_detections)
matches_to_extend = get_matches_from_detection_mappings(
Expand Down
Loading