Skip to content

Commit d297421

Browse files
committed
Format code and fix logging #2343
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent c3d9769 commit d297421

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/cluecode/plugin_filter_clues.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def filter_ignorable_resource_clues(resource, rules_by_id):
9090
if hasattr(resource, 'holders'):
9191
resource.holders = filtered.holders
9292
if hasattr(resource, 'copyrights'):
93-
resource.copyrights = filtered.copyrights
93+
resource.copyrights = filtered.copyrights
9494
return resource
9595

9696

@@ -209,7 +209,7 @@ def filter_ignorable_clues(detections, rules_by_id):
209209
no_detected_ignorables = not detections.copyrights and not detections.authors
210210

211211
ignorables = collect_ignorables(detections.licenses, rules_by_id)
212-
212+
213213
no_ignorables = not detections.licenses or is_empty(ignorables)
214214

215215
if TRACE:
@@ -224,36 +224,45 @@ def filter_ignorable_clues(detections, rules_by_id):
224224
attributes=detections.emails,
225225
ignorables=ignorables.emails.union(
226226
detections.copyrights_as_ignorable,
227-
detections.authors_as_ignorable),
228-
value_key='email'))
227+
detections.authors_as_ignorable,
228+
),
229+
value_key='email',
230+
))
229231

230232
# discard redundant urls if ignorable or in a detected copyright or author
231233
urls = list(filter_values(
232234
attributes=detections.urls,
233235
ignorables=ignorables.urls.union(
234236
detections.copyrights_as_ignorable,
235-
detections.authors_as_ignorable),
236-
value_key='url', strip='/'))
237+
detections.authors_as_ignorable,
238+
),
239+
value_key='url',
240+
strip='/',
241+
))
237242

238243
# discard redundant authors if ignorable or in detected holders or copyrights
239244
authors = list(filter_values(
240245
attributes=detections.authors,
241246
ignorables=ignorables.authors.union(
242247
detections.copyrights_as_ignorable,
243-
detections.holders_as_ignorable),
244-
value_key='value'))
248+
detections.holders_as_ignorable,
249+
),
250+
value_key='value',
251+
))
245252

246253
# discard redundant holders if ignorable
247254
holders = list(filter_values(
248255
attributes=detections.holders,
249256
ignorables=ignorables.holders,
250-
value_key='value'))
257+
value_key='value',
258+
))
251259

252260
# discard redundant copyrights if ignorable
253261
copyrights = list(filter_values(
254262
attributes=detections.copyrights,
255263
ignorables=ignorables.copyrights,
256-
value_key='value'))
264+
value_key='value',
265+
))
257266

258267
return Detections(
259268
copyrights=copyrights,
@@ -281,22 +290,26 @@ def filter_values(attributes, ignorables, value_key='value', strip=''):
281290
el = item['end_line']
282291
val = item[value_key].strip(strip)
283292
ignored = False
293+
284294
if TRACE:
285295
logger_debug(' filter_values: ignorables:', ignorables)
296+
286297
for ign in ignorables:
287298
if TRACE: logger_debug(' filter_values: ign:', ign)
288299
if (ls in ign.lines_range or el in ign.lines_range) and val in ign.value:
289300
ignored = True
290301
if TRACE: logger_debug(' filter_values: skipped')
291302
break
303+
292304
if not ignored:
293305
yield item
294306

295307

296308
def collect_ignorables(license_matches, rules_by_id):
297309
"""
298-
Collect and return an ignorable Clues object built from `license_matches` matched licenses
299-
which is the list of "licenses" objects returned in JSON results.
310+
Collect and return an ignorable Clues object built from `license_matches`
311+
matched licenses which is the list of "licenses" objects returned in JSON
312+
results.
300313
301314
The value of each ignorable list of clues is a set of (set of
302315
lines number, set of ignorable values). The return values is a mapping
@@ -360,6 +373,9 @@ def collect_ignorables(license_matches, rules_by_id):
360373
if ign_urls:
361374
urls.add(Ignorable(lines_range=lines_range, value=ign_urls))
362375

376+
if TRACE:
377+
logger_debug(' collect_ignorables: rule:', rule)
378+
363379
ignorables = Ignorables(
364380
copyrights=frozenset(copyrights),
365381
holders=frozenset(holders),
@@ -369,7 +385,6 @@ def collect_ignorables(license_matches, rules_by_id):
369385
)
370386

371387
if TRACE:
372-
logger_debug(' collect_ignorables: rule:', rule)
373388
logger_debug(' collect_ignorables: ignorables:', ignorables)
374389

375390
return ignorables

0 commit comments

Comments
 (0)