Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parse the Pylint message list
import pathlib
import re
SUMMARY_LINE_RE = re.compile(r':(?P<name>\S+) \((?P<code>.+?)\):( \*(?P<summary>.+)\*)?')
def parse_summary_line(line):
line_match = SUMMARY_LINE_RE.match(line)
if not line_match:
raise ValueError(f"ill-formed line: {line!r}")
parts = line_match.groupdict()
return parts['name'], parts['code'], parts.get('summary')
def filter_summary_lines(lines):
for line in lines:
if line.startswith(':'):
yield line
def main(msgs_list):
error_codes = []
for line in filter_summary_lines(msgs_list.splitlines()):
_, code, _ = parse_summary_line(line)
if code.startswith('E'):
error_codes.append(code)
print(','.join(sorted(error_codes)))
if __name__ == '__main__':
import sys
if len(sys.argv) == 1: # Pipe
main(sys.stdin.read())
elif len(sys.argv) == 2: # File path
with open(sys.argv[1], encoding='utf-8') as file:
main(file.read())
else: # Beats me
raise RuntimeError('too many CLI arguments')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment