Skip to content
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The following organizations or individuals have contributed to ScanCode:
- Daniel Eder @daniel-eder
- Dan Kegel @dankegel
- Dennis Clark @DennisClark
- Dhruv @DHRUV-1-star
- Divyansh Sharma @Divyansh2512
- Duncan Howe @Duncan-Howe
- Felix Kauselmann @selmf
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Next release

- Improve copyright detection for statements with parens or trailing "authors"

- Improve author detection for compact declarations and dotted author names.
https://github.com/aboutcode-org/scancode-toolkit/issues/4229

- Add experimental option for using cached results during scan time. When the
``--use-cached-results`` option is enabled in the ScanCode CLI, during scan
time for a given Resource, we iterate through the active scanners and see if we
Expand Down
15 changes: 15 additions & 0 deletions src/cluecode/copyrights.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,21 @@ def get_tokens(numbered_lines, splitter=re.compile(r'[\t =;]+').split):
# space before in some cases: exclude (digit , (s , (c , (-
# this allows to recover from words like KISA(Korean
line = re.sub(pattern=r'(\([^rsc\-\d])', repl=r' \g<1>', string=line)

# Split compact author prefix such as Author:Frankie.Chu while
# preserving colons elsewhere (e.g. in URLs).
line = re.sub(
pattern=r'(^|\s)([Aa]uthors?):(?=\S)',
repl=r'\1\2: ',
string=line,
)

# Normalize dotted names only when they follow an Author tag.
line = re.sub(
pattern=r'(^|\s)([Aa]uthors?):\s+([A-Z][a-z]+)\.([A-Z][a-z]+)(?=\b|[,;])',
repl=r'\1\2 \3 \4',
string=line,
)
for tok in splitter(line):
# strip trailing quotes+comma
if tok.endswith("',"):
Expand Down
32 changes: 32 additions & 0 deletions tests/cluecode/test_copyrights_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,38 @@ def test_detect_with_lines_only_holders(self):
))
assert results == expected

def test_detect_author_without_space_and_with_dotted_name(self):
numbered_lines = [
(1, '// Date:9 April,2012'),
(2, '// Author:Frankie.Chu'),
]
expected = [
copyrights.AuthorDetection('Frankie Chu', 2, 2),
]
results = list(copyrights.detect_copyrights_from_lines(
numbered_lines,
include_copyrights=False,
include_holders=False,
include_authors=True,
))
assert results == expected

def test_detect_author_with_space_and_with_dotted_name(self):
numbered_lines = [
(1, '// Date:9 April,2012'),
(2, '// Author: Frankie.Chu'),
]
expected = [
copyrights.AuthorDetection('Frankie Chu', 2, 2),
]
results = list(copyrights.detect_copyrights_from_lines(
numbered_lines,
include_copyrights=False,
include_holders=False,
include_authors=True,
))
assert results == expected


def check_full_detections(expected, test_file):
"""
Expand Down
Loading