Skip to content

Commit ad4dfff

Browse files
committed
Refine license tests
And spell spurious with one r, not two. Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent ba249d1 commit ad4dfff

14 files changed

Lines changed: 38 additions & 37 deletions

File tree

src/licensedcode/data/licenses/d-fsl-1.0-en.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ name: German Free Software License
44
category: Copyleft
55
owner: Institute for Legal Issues On Free and Open Source Software
66
homepage_url: http://www.dipp.nrw.de/d-fsl/index_html/lizenzen/en/D-FSL-1_0_en.txt
7-
spdx_license_key: LicenseRef-scancode-d-fsl-1.0-en
7+
spdx_license_key: D-FSL-1.0
8+
other_spdx_license_keys:
9+
- LicenseRef-scancode-d-fsl-1.0-en
810
text_urls:
911
- http://www.dipp.nrw.de/d-fsl/index_html/lizenzen/en/D-FSL-1_0_en.txt
1012
faq_url: http://www.d-fsl.org/

src/licensedcode/match.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
3232
- containment: a small match is contained in a larger match
3333
- overlap: based on a level of overlap between matches
34-
- various spurrious matches rules based on length, required content, etc.
34+
- various spurious matches rules based on length, required content, etc.
3535
- false positives
3636
3737
The filter functions are executed in a specific sequence over the list of matches.
@@ -48,7 +48,7 @@
4848
TRACE_FILTER_SHORT = False
4949
TRACE_FILTER_RULE_MIN_COVERAGE = False
5050
TRACE_FILTER_BELOW_MIN_SCORE = False
51-
TRACE_FILTER_SINGLE_WORD_BINARY = False
51+
TRACE_FILTER_SINGLE_WORD_GIBBERISH = False
5252
TRACE_SET_LINES = False
5353
TRACE_KEY_PHRASES = False
5454
TRACE_REGIONS = False
@@ -81,7 +81,7 @@ def logger_debug(*args): pass
8181
or TRACE_SET_LINES
8282
or TRACE_MATCHED_TEXT
8383
or TRACE_MATCHED_TEXT_DETAILS
84-
or TRACE_FILTER_SINGLE_WORD_BINARY
84+
or TRACE_FILTER_SINGLE_WORD_GIBBERISH
8585
or TRACE_KEY_PHRASES
8686
or TRACE_REGIONS
8787
or TRACE_FILTER_LICENSE_LIST
@@ -128,7 +128,7 @@ class DiscardReason(IntEnum):
128128
SPURIOUS_SINGLE_TOKEN = 3
129129
TOO_SHORT = 4
130130
SCATTERED_ON_TOO_MANY_LINES = 5
131-
INVALID_SINGLE_WORD_IN_BINARY = 6
131+
INVALID_SINGLE_WORD_GIBBERISH = 6
132132
SPURIOUS = 7
133133
CONTAINED = 8
134134
OVERLAPPING = 9
@@ -1697,24 +1697,25 @@ def filter_spurious_matches(
16971697
return kept, discarded
16981698

16991699

1700-
def filter_invalid_matches_to_single_word_in_binaries(
1700+
def filter_invalid_matches_to_single_word_gibberish(
17011701
matches,
1702-
trace=TRACE_FILTER_SINGLE_WORD_BINARY,
1703-
reason=DiscardReason.INVALID_SINGLE_WORD_IN_BINARY,
1702+
trace=TRACE_FILTER_SINGLE_WORD_GIBBERISH,
1703+
reason=DiscardReason.INVALID_SINGLE_WORD_GIBBERISH,
17041704
):
17051705
"""
17061706
Return a filtered list of kept LicenseMatch matches and a list of
17071707
discardable matches given a `matches` list of LicenseMatch by removing
1708-
matches in binary files considered as invalid under these conditions:
1708+
gibberish matches considered as invalid under these conditions:
17091709
1710-
- the match is for a binary file
1711-
- the matched rule that has a single word (length 1)
1710+
- the scanned file is a binary file (we could relax this in the future
1711+
- the matched rule has a single word (length 1)
1712+
- the matched rule "is_license_reference: yes"
17121713
- the matched rule has a low relevance, e.g., under 75
17131714
- the matched text has either:
17141715
- one or more leading or trailing punctuations (except for +)
17151716
unless this has a high relevance and the rule is contained as-is
17161717
in the matched text (considering case)
1717-
- mixed upper and lower case charcaters (but not a Title case) unless
1718+
- mixed upper and lower case characters (but not a Title case) unless
17181719
exactly the same mixed case as the rule text
17191720
"""
17201721
kept = []
@@ -1724,11 +1725,7 @@ def filter_invalid_matches_to_single_word_in_binaries(
17241725

17251726
for match in matches:
17261727
rule = match.rule
1727-
if (
1728-
rule.length == 1
1729-
and match.query.is_binary
1730-
and rule.is_license_reference
1731-
):
1728+
if rule.length == 1 and rule.is_license_reference and match.query.is_binary:
17321729
matched_text = match.matched_text(
17331730
whole_lines=False,
17341731
highlight=False,
@@ -1738,7 +1735,7 @@ def filter_invalid_matches_to_single_word_in_binaries(
17381735

17391736
if trace:
17401737
logger_debug(
1741-
' ==> POTENTIAL INVALID_BINARY:', match,
1738+
' ==> POTENTIAL INVALID GIBBERISH:', match,
17421739
'matched_text:', repr(matched_text),
17431740
'rule_text:', repr(rule_text)
17441741
)
@@ -1750,7 +1747,7 @@ def filter_invalid_matches_to_single_word_in_binaries(
17501747

17511748
if is_invalid_short_match(matched_text, rule_text, max_diff=max_diff):
17521749
if trace:
1753-
logger_debug(' ==> DISCARDING INVALID_BINARY:', match)
1750+
logger_debug(' ==> DISCARDING INVALID GIBBERISH:', match)
17541751
discarded_append(match)
17551752
match.discard_reason = reason
17561753
continue
@@ -1808,7 +1805,7 @@ def is_invalid_short_match(
18081805
matched_text,
18091806
rule_text,
18101807
max_diff=0,
1811-
trace=TRACE_FILTER_SINGLE_WORD_BINARY,
1808+
trace=TRACE_FILTER_SINGLE_WORD_GIBBERISH,
18121809
):
18131810
"""
18141811
Return True if the ``matched_text`` given a ``rule_text`` is invalid.
@@ -1842,6 +1839,8 @@ def is_invalid_short_match(
18421839
False
18431840
>>> is_invalid_short_match("gpl) &", "GPL")
18441841
True
1842+
>>> is_invalid_short_match("GPLv2(", "GPLv2")
1843+
True
18451844
"""
18461845
if trace:
18471846
logger_debug(
@@ -1973,9 +1972,9 @@ def filter_matches_missing_key_phrases(
19731972
continue
19741973

19751974
if is_continuous and not match.is_continuous():
1976-
kept_append(match)
1975+
discarded_append(match)
19771976
if trace:
1978-
logger_debug(' ==> KEEPING, IS_CONTINUOUS BUT NOT IS_CONTINUOUS')
1977+
logger_debug(' ==> DISCARDING, IS_CONTINUOUS BUT NOT IS_CONTINUOUS')
19791978
continue
19801979

19811980
ispan = match.ispan
@@ -2528,9 +2527,9 @@ def _log(_matches, _discarded, msg):
25282527
all_discarded_extend(discarded)
25292528
_log(matches, discarded, 'ACCEPTABLE IF NOT SHORT SCATTERED')
25302529

2531-
matches, discarded = filter_invalid_matches_to_single_word_in_binaries(matches)
2530+
matches, discarded = filter_invalid_matches_to_single_word_gibberish(matches)
25322531
all_discarded_extend(discarded)
2533-
_log(matches, discarded, 'MORE THAN ONE NON INVALID TOKEN IN BINARY')
2532+
_log(matches, discarded, 'MORE THAN ONE NON INVALID GIBBERISH TOKEN')
25342533

25352534
matches, discarded = filter_spurious_matches(matches)
25362535
all_discarded_extend(discarded)

src/packagedcode/debian_copyright.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ def clean_expression(text):
14001400
def remove_known_license_intros(license_matches):
14011401
"""
14021402
Return a filtered ``license_matches`` list of LicenseMatch objects removing
1403-
spurrious matches to license introduction statements (e.g.
1403+
spurious matches to license introduction statements (e.g.
14041404
`is_license_intro` Rules.)
14051405
14061406
A common source of false positive license detections in unstructured files

tests/licensedcode/data/datadriven/external/fossology-tests/Apache/license.txt.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ license_expressions:
1212
- other-permissive
1313
- apache-2.0
1414
- apache-2.0
15-
- apache-2.0
1615
- lgpl-2.0-plus
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{gpl}}
1+
GPL
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
license_expression: gpl-1.0
2-
is_license_text: yes
2+
is_license_reference: yes
33
relevance: 50
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{gpl 10}}
1+
{{GPL 10}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
license_expression: gpl-1.0
2-
is_license_tag: yes
2+
is_license_reference: yes
33
relevance: 100
44
is_continuous: yes
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{gpl 20}}
1+
{{GPL 20}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
license_expression: gpl-2.0
2-
is_license_tag: yes
2+
is_license_reference: yes
33
relevance: 100
44
is_continuous: yes

0 commit comments

Comments
 (0)