Skip to content

Instantly share code, notes, and snippets.

@brettcannon
Last active March 9, 2018 19:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brettcannon/eff7f38a60af48d39814cbb2f33b3d1d to your computer and use it in GitHub Desktop.
Save brettcannon/eff7f38a60af48d39814cbb2f33b3d1d to your computer and use it in GitHub Desktop.
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