|
10 | 10 |
|
11 | 11 | import os |
12 | 12 | import sys |
| 13 | +import re |
13 | 14 |
|
14 | 15 | from collections import deque |
15 | 16 |
|
| 17 | + |
16 | 18 | from commoncode.fileutils import file_name |
17 | 19 |
|
18 | 20 | """ |
|
25 | 27 | P: 3F69 2E64 6D92 3BBE E7AE 9258 5C0F 96E8 4EC1 6D6B |
26 | 28 | B: 1DwxWb2J4vuX4vjsbzaCXW696rZfeamahz |
27 | 29 |
|
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 |
29 | 36 | """ |
30 | 37 | # Tracing flags |
31 | 38 | TRACE = False or os.environ.get('SCANCODE_DEBUG_CREDITS', False) |
@@ -103,17 +110,29 @@ def detect_credits_authors_from_lines(numbered_lines): |
103 | 110 | names = [] |
104 | 111 | emails = [] |
105 | 112 | webs = [] |
| 113 | + authors = [] |
| 114 | + |
106 | 115 | 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 | + |
109 | 120 | if ltype == "N": |
110 | | - names.append(line) |
| 121 | + names.append(line_value) |
111 | 122 | elif ltype == "E": |
112 | | - emails.append(line) |
| 123 | + emails.append(line_value) |
113 | 124 | 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) |
117 | 136 | if TRACE: |
118 | 137 | logger_debug('detect_credits_authors_from_lines: items:', items) |
119 | 138 |
|
@@ -142,7 +161,8 @@ def get_credit_lines_groups(numbered_lines): |
142 | 161 | yield list(lines_group) |
143 | 162 | lines_group_clear() |
144 | 163 |
|
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): |
146 | 166 | has_credits = True |
147 | 167 | lines_group_append((ln, line)) |
148 | 168 |
|
|
0 commit comments