Skip to content

Instantly share code, notes, and snippets.

@jgonera
Created August 22, 2022 17:10
Show Gist options
  • Save jgonera/317cba59d12bc6bf287322daf36c5119 to your computer and use it in GitHub Desktop.
Save jgonera/317cba59d12bc6bf287322daf36c5119 to your computer and use it in GitHub Desktop.
"""
Generates per-file-ignores section for the .flake8 configuration file based on
flake8 run output (can be either piped using STDIN or read from the file as the
first argument to this script).
Use this to disable some linting in legacy code, but keep full linting for
newly written code.
"""
import fileinput
from collections import defaultdict
per_file_ignores = defaultdict(set)
for line in fileinput.input():
path, line, column, error = line.split(":", 3)
code, message = error.strip().split(" ", 1)
per_file_ignores[path].add(code)
for path, codes in per_file_ignores.items():
print(f"{path}:{','.join(codes)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment