Skip to content

Commit b8544b1

Browse files
committed
Add doc-strings
Signed-off-by: akugarg <akanksha.garg2k@gmail.com>
1 parent f21a875 commit b8544b1

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/licensedcode/plugin_license.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ def process_codebase(self, codebase, **kwargs):
129129

130130
def match_reference_license(resource, codebase):
131131
"""
132-
Return the updated license matches having reference to another files
132+
Return the ``resource`` Resource updating and saving it in place, after adding new
133+
icense matches (licenses and license_expressions) following their Rule
134+
``referenced_filenames`` if any. Return None if this is not a file Resource.
133135
"""
134136
if not resource.is_file:
135137
return
@@ -142,16 +144,20 @@ def match_reference_license(resource, codebase):
142144
referenced_licenses = []
143145
referenced_license_expressions = []
144146
referenced_filenames = get_referenced_filenames(licenses)
147+
modified = False
145148

146149
for referenced_filename in referenced_filenames:
147150
new_resource = find_referenced_resource(referenced_filename=referenced_filename, resource=resource, codebase=codebase)
148151
if new_resource:
152+
modified = True
149153
referenced_licenses.extend(new_resource.licenses)
150154
referenced_license_expressions.extend(new_resource.license_expressions)
151155

152156
licenses.extend(referenced_licenses)
153157
license_expressions.extend(referenced_license_expressions)
154-
codebase.save_resource(resource)
158+
159+
if modified:
160+
codebase.save_resource(resource)
155161
return resource
156162

157163

@@ -171,7 +177,9 @@ def get_referenced_filenames(license_matches):
171177

172178
def find_referenced_resource(referenced_filename, resource, codebase, **kwargs):
173179
"""
174-
Return the resource object for matching referenced-filename given a resource in codebase
180+
Return a Resource matching the ``referenced_filename`` path or filename given a ``resource`` in ``codebase``.
181+
Return None if the ``referenced_filename`` cannot be found in the same directory as the base ``resource``.
182+
``referenced_filename`` is the path or filename referenced in a LicenseMatch of ``resource``,
175183
"""
176184
parent = resource.parent(codebase)
177185

0 commit comments

Comments
 (0)