Skip to content

Commit f030eb3

Browse files
authored
Merge pull request #2343 from VanL/fix-is-empty-logic
Modify is_empty to fix logic error
2 parents 498defa + c79e2f5 commit f030eb3

File tree

10 files changed

+609
-16
lines changed

10 files changed

+609
-16
lines changed

src/cluecode/plugin_filter_clues.py

Lines changed: 32 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

@@ -191,6 +191,10 @@ def is_empty(clues):
191191
if clues:
192192
return not any([
193193
clues.copyrights, clues.holders, clues.authors, clues.urls, clues.emails])
194+
else:
195+
# The logic is reversed, so a false or None "clues" object returns None, which
196+
# is interpreted as False (i.e., the object is *not* empty).
197+
return True
194198

195199

196200
def filter_ignorable_clues(detections, rules_by_id):
@@ -205,7 +209,7 @@ def filter_ignorable_clues(detections, rules_by_id):
205209
no_detected_ignorables = not detections.copyrights and not detections.authors
206210

207211
ignorables = collect_ignorables(detections.licenses, rules_by_id)
208-
212+
209213
no_ignorables = not detections.licenses or is_empty(ignorables)
210214

211215
if TRACE:
@@ -220,36 +224,45 @@ def filter_ignorable_clues(detections, rules_by_id):
220224
attributes=detections.emails,
221225
ignorables=ignorables.emails.union(
222226
detections.copyrights_as_ignorable,
223-
detections.authors_as_ignorable),
224-
value_key='email'))
227+
detections.authors_as_ignorable,
228+
),
229+
value_key='email',
230+
))
225231

226232
# discard redundant urls if ignorable or in a detected copyright or author
227233
urls = list(filter_values(
228234
attributes=detections.urls,
229235
ignorables=ignorables.urls.union(
230236
detections.copyrights_as_ignorable,
231-
detections.authors_as_ignorable),
232-
value_key='url', strip='/'))
237+
detections.authors_as_ignorable,
238+
),
239+
value_key='url',
240+
strip='/',
241+
))
233242

234243
# discard redundant authors if ignorable or in detected holders or copyrights
235244
authors = list(filter_values(
236245
attributes=detections.authors,
237246
ignorables=ignorables.authors.union(
238247
detections.copyrights_as_ignorable,
239-
detections.holders_as_ignorable),
240-
value_key='value'))
248+
detections.holders_as_ignorable,
249+
),
250+
value_key='value',
251+
))
241252

242253
# discard redundant holders if ignorable
243254
holders = list(filter_values(
244255
attributes=detections.holders,
245256
ignorables=ignorables.holders,
246-
value_key='value'))
257+
value_key='value',
258+
))
247259

248260
# discard redundant copyrights if ignorable
249261
copyrights = list(filter_values(
250262
attributes=detections.copyrights,
251263
ignorables=ignorables.copyrights,
252-
value_key='value'))
264+
value_key='value',
265+
))
253266

254267
return Detections(
255268
copyrights=copyrights,
@@ -277,22 +290,26 @@ def filter_values(attributes, ignorables, value_key='value', strip=''):
277290
el = item['end_line']
278291
val = item[value_key].strip(strip)
279292
ignored = False
293+
280294
if TRACE:
281295
logger_debug(' filter_values: ignorables:', ignorables)
296+
282297
for ign in ignorables:
283298
if TRACE: logger_debug(' filter_values: ign:', ign)
284299
if (ls in ign.lines_range or el in ign.lines_range) and val in ign.value:
285300
ignored = True
286301
if TRACE: logger_debug(' filter_values: skipped')
287302
break
303+
288304
if not ignored:
289305
yield item
290306

291307

292308
def collect_ignorables(license_matches, rules_by_id):
293309
"""
294-
Collect and return an ignorable Clues object built from `license_matches` matched licenses
295-
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.
296313
297314
The value of each ignorable list of clues is a set of (set of
298315
lines number, set of ignorable values). The return values is a mapping
@@ -356,6 +373,9 @@ def collect_ignorables(license_matches, rules_by_id):
356373
if ign_urls:
357374
urls.add(Ignorable(lines_range=lines_range, value=ign_urls))
358375

376+
if TRACE:
377+
logger_debug(' collect_ignorables: rule:', rule)
378+
359379
ignorables = Ignorables(
360380
copyrights=frozenset(copyrights),
361381
holders=frozenset(holders),
@@ -365,7 +385,6 @@ def collect_ignorables(license_matches, rules_by_id):
365385
)
366386

367387
if TRACE:
368-
logger_debug(' collect_ignorables: rule:', rule)
369388
logger_debug(' collect_ignorables: ignorables:', ignorables)
370389

371390
return ignorables
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Permission to use, copy, modify, and distribute this software and its
2+
documentation for any purpose, without fee, and without a written
3+
agreement is hereby granted, provided that the above copyright notice and
4+
this paragraph and the following two paragraphs appear in all copies or in
5+
any new file that contains a substantial portion of this file.
6+
7+
IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
8+
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
9+
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE
10+
AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11+
12+
THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
13+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
14+
PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
15+
AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
16+
ENHANCEMENTS, OR MODIFICATIONS.
17+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
license_expression: pygres-2.2
2+
is_license_text: yes
3+
notes: from http://shell.vex.net/viewvc.cgi/pygresql/trunk/module/pgmodule.c?view=markup&pathrev=431
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
Copyright (c) The Eclipse Foundation
3+
https://eclipse.org
4+
5+
author: John Doe
6+
7+
is licensed under the
8+
Apache Software License, Version 1.1, which is reproduced below.
9+
10+
/*
11+
* The Apache Software License, Version 1.1
12+
*
13+
*
14+
* Copyright (c) The Apache Software Foundation. All rights
15+
* reserved.
16+
*
17+
* Redistribution and use in source and binary forms, with or without
18+
* modification, are permitted provided that the following conditions
19+
* are met:
20+
*
21+
* 1. Redistributions of source code must retain the above copyright
22+
* notice, this list of conditions and the following disclaimer.
23+
*
24+
* 2. Redistributions in binary form must reproduce the above copyright
25+
* notice, this list of conditions and the following disclaimer in
26+
* the documentation and/or other materials provided with the
27+
* distribution.
28+
*
29+
* 3. The end-user documentation included with the redistribution,
30+
* if any, must include the following acknowledgment:
31+
* "This product includes software developed by the
32+
* Apache Software Foundation (http://www.apache.org/)."
33+
* Alternately, this acknowledgment may appear in the software itself,
34+
* if and wherever such third-party acknowledgments normally appear.
35+
*
36+
* 4. The names "Xerces" and "Apache Software Foundation" must
37+
* not be used to endorse or promote products derived from this
38+
* software without prior written permission. For written
39+
* permission, please contact [email protected].
40+
41+
Copyright (c) The Eclipse Foundation
42+
https://eclipse.org
43+
44+
author: John Doe
45+
46+
*
47+
* 5. Products derived from this software may not be called "Apache",
48+
* nor may "Apache" appear in their name, without prior written
49+
* permission of the Apache Software Foundation.
50+
*
51+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
52+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
54+
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
55+
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
58+
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
59+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
60+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
61+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62+
* SUCH DAMAGE.
63+
* ====================================================================
64+
*
65+
* This software consists of voluntary contributions made by many
66+
* individuals on behalf of the Apache Software Foundation and was
67+
* originally based on software copyright (c) 1999, International
68+
* Business Machines, Inc., http://www.ibm.com. For more
69+
* information on the Apache Software Foundation, please see
70+
* <http://www.apache.org/>.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
* $Id$
2+
* PyGres, version 2.2 A Python interface for PostgreSQL database. Written by
3+
* D'Arcy John Cain, ([email protected]). Based heavily on code written by
4+
* Pascal Andre, [email protected]. Copyright (c) 1996, Pascal Andre
5+
6+
*
7+
* Permission to use, copy, modify, and distribute this software and its
8+
* documentation for any purpose, without fee, and without a written
9+
* agreement is hereby granted, provided that the above copyright notice and
10+
* this paragraph and the following two paragraphs appear in all copies or in
11+
* any new file that contains a substantial portion of this file.
12+
*
13+
* IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
14+
* SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
15+
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE
16+
* AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17+
*
18+
* THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
19+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20+
* PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
21+
* AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
22+
* ENHANCEMENTS, OR MODIFICATIONS.
23+
*
24+
* Further modifications copyright 1997, 1998, 1996 by D'Arcy John. Cain
25+
* ([email protected]) subject to the same terms and conditions as above.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
PCRE LICENCE
2+
------------
3+
4+
PCRE is a library of functions to support regular expressions whose
5+
syntax and semantics are as close as possible to those of the Perl 5
6+
language.
7+
8+
Written by: Philip Hazel <[email protected]>
9+
University of Cambridge Computing Service, Cambridge, England.
10+
Phone: +44 1223 334714.
11+
Copyright (c) 1997-2001 University of Cambridge
12+
13+
Permission is granted to anyone to use this software for any purpose on
14+
any computer system, and to redistribute it freely, subject to the
15+
following restrictions:
16+
17+
1. This software is distributed in the hope that it will be useful, but
18+
WITHOUT ANY WARRANTY; without even the implied warranty of
19+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20+
21+
2. The origin of this software must not be misrepresented, either by
22+
explicit claim or by omission. In practice, this means that if you use
23+
PCRE in software which you distribute to others, commercially or
24+
otherwise, you must put a sentence like this
25+
"Regular expression support is provided by the PCRE library package,
26+
which is open source software, written by Philip Hazel, and copyright by
27+
the University of Cambridge, England"
28+
29+
somewhere reasonably visible in your documentation and in any relevant
30+
files or online help data or similar.
31+
32+
A reference to the ftp site for the source, that is, to
33+
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
34+
should also be given in the documentation.
35+
36+
3. Altered versions must be plainly marked as such, and must not be
37+
misrepresented as being the original software.
38+
39+
4. If PCRE is embedded in any software that is released under the GNU
40+
General Purpose Licence (GPL), or Lesser General Purpose Licence (LGPL),
41+
then the terms of that licence shall supersede any condition above with
42+
which it is incompatible.
43+
44+
The documentation for PCRE, supplied in the "doc" directory, is
45+
distributed under the same terms as the software itself.
46+
47+
End PCRE LICENCE

0 commit comments

Comments
 (0)