1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 16:27:13 +03:00

l10n script: Only report 'Unknown comment' if we didn't find a LANG one

So if we have a before LANG comment, then don't report the actual line
for a bad comment.

And if we have a current_line valid LANG comment, then don't report the
above_line as unknown.
This commit is contained in:
Athanasius 2021-06-07 15:27:09 +01:00
parent 06725467f9
commit 1b58e91fa2

View File

@ -64,38 +64,36 @@ def extract_comments(call: ast.Call, lines: list[str], file: pathlib.Path) -> Op
:param file: The path to the file this call node came from
:return: The first comment that matches the rules, or None
"""
out: list[Optional[str]] = []
out: Optional[str] = None
above = call.lineno - 2
current = call.lineno - 1
above_line = lines[above].strip() if len(lines) >= above else None
current_line = lines[current].strip()
bad_comment: Optional[str] = None
for line in (above_line, current_line):
if line is None or '#' not in line:
out.append(None)
continue
match = COMMENT_RE.match(line)
if not match:
print(line)
out.append(None)
continue
comment = match.group(1).strip()
if not comment.startswith('# LANG:'):
print(f'Unknown comment for {file}:{current} {line}', file=sys.stderr)
out.append(None)
bad_comment = f'Unknown comment for {file}:{current} {line}'
continue
out.append(comment.replace('# LANG:', '').strip())
out = comment.replace('# LANG:', '').strip()
bad_comment = None
break
if out[1] is not None:
return out[1]
elif out[0] is not None:
return out[0]
if bad_comment is not None:
print(bad_comment, file=sys.stderr)
return None
return out
def scan_file(path: pathlib.Path) -> list[ast.Call]: