MCPcopy Create free account
hub / github.com/espnet/espnet / parse_pycodestyle_output

Function parse_pycodestyle_output

utils/apply_code_fixes.py:79–162  ·  view source on GitHub ↗

Parse pycodestyle output and group issues by file. Args: output: The output from pycodestyle. Returns: A dictionary mapping file paths to lists of issues.

(output: str)

Source from the content-addressed store, hash-verified

77
78
79def parse_pycodestyle_output(output: str) -> Dict[str, List[Dict[str, str]]]:
80 """Parse pycodestyle output and group issues by file.
81
82 Args:
83 output: The output from pycodestyle.
84
85 Returns:
86 A dictionary mapping file paths to lists of issues.
87 """
88 issues_by_file = defaultdict(list)
89
90 # Pattern to match pycodestyle output lines
91 # Example: file.py:123:4: E101 indentation contains mixed spaces and tabs
92 pattern = r"^(.+?):(\d+):(\d+): ([A-Z]\d+) (.+)$"
93
94 current_file = None
95 current_line = None
96 current_column = None
97 current_code = None
98 current_message = None
99 source_lines = []
100 pep8_lines = []
101
102 in_source = False
103 in_pep8 = False
104
105 for line in output.split("\n"):
106 match = re.match(pattern, line)
107
108 if match:
109 # If we were processing an issue, save it before starting a new one
110 if current_file and current_line and current_code and current_message:
111 issues_by_file[current_file].append(
112 {
113 "line": current_line,
114 "column": current_column,
115 "code": current_code,
116 "message": current_message,
117 "source": "\n".join(source_lines),
118 "pep8": "\n".join(pep8_lines),
119 }
120 )
121 source_lines = []
122 pep8_lines = []
123
124 # Start a new issue
125 current_file = match.group(1)
126 current_line = match.group(2)
127 current_column = match.group(3)
128 current_code = match.group(4)
129 current_message = match.group(5)
130 in_source = False
131 in_pep8 = False
132 elif line.strip() == "":
133 # Empty line toggles between source and PEP8 reference
134 if in_source:
135 in_source = False
136 in_pep8 = True

Callers 1

mainFunction · 0.85

Calls 2

appendMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…