Skip to content

Commit a5b4d18

Browse files
committed
Fix author extraction for 'Author:Name' format without space
1 parent 7dbb3c7 commit a5b4d18

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/cluecode/linux_credits.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
import os
1212
import sys
13+
import re
1314

1415
from collections import deque
1516

17+
1618
from commoncode.fileutils import file_name
1719

1820
"""
@@ -25,7 +27,12 @@
2527
P: 3F69 2E64 6D92 3BBE E7AE 9258 5C0F 96E8 4EC1 6D6B
2628
B: 1DwxWb2J4vuX4vjsbzaCXW696rZfeamahz
2729
28-
We only consider the entries: N: name, E: email and W: web URL
30+
We only consider the entries: N: name, E: email and W: web URL.
31+
Additionally, we support Author and Upstream Author formats:
32+
Author: Author Name
33+
Author:Author Name (no space after colon)
34+
Upstream Author: Author Name
35+
Upstream-Author: Author Name
2936
"""
3037
# Tracing flags
3138
TRACE = False or os.environ.get('SCANCODE_DEBUG_CREDITS', False)
@@ -103,17 +110,29 @@ def detect_credits_authors_from_lines(numbered_lines):
103110
names = []
104111
emails = []
105112
webs = []
113+
authors = []
114+
106115
for _, line in lines:
107-
ltype, _, line = line.partition(":")
108-
line = line.strip()
116+
# Extract the type and value using partition for N:, E:, W: format
117+
ltype, _, line_value = line.partition(":")
118+
line_value = line_value.strip()
119+
109120
if ltype == "N":
110-
names.append(line)
121+
names.append(line_value)
111122
elif ltype == "E":
112-
emails.append(line)
123+
emails.append(line_value)
113124
elif ltype == "W":
114-
webs.append(line)
115-
116-
items = list(" ".join(item) for item in (names, emails, webs) if item)
125+
webs.append(line_value)
126+
else:
127+
# Handle Author: format (with or without space after colon)
128+
# Extract author name using regex to handle both "Author:Name" and "Author: Name"
129+
match = re.match(r'^(?:Author|Upstream[-\s]*Author):\s*(.+)$', line, re.IGNORECASE)
130+
if match:
131+
author_name = match.group(1).strip()
132+
if author_name:
133+
authors.append(author_name)
134+
135+
items = list(" ".join(item) for item in (names, emails, webs, authors) if item)
117136
if TRACE:
118137
logger_debug('detect_credits_authors_from_lines: items:', items)
119138

@@ -142,7 +161,8 @@ def get_credit_lines_groups(numbered_lines):
142161
yield list(lines_group)
143162
lines_group_clear()
144163

145-
if line.startswith(("N:", "E:", "W:")):
164+
# Support both standard format (N:, E:, W:) and Author: format (with or without space after colon)
165+
if line.startswith(("N:", "E:", "W:")) or re.match(r'^(?:Author|Upstream[-\s]*Author):\s*', line, re.IGNORECASE):
146166
has_credits = True
147167
lines_group_append((ln, line))
148168

0 commit comments

Comments
 (0)