-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_f401.py
More file actions
25 lines (23 loc) · 869 Bytes
/
debug_f401.py
File metadata and controls
25 lines (23 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3
import subprocess
result = subprocess.run(['python', '-m', 'flake8', 'scripts/agent', '--max-line-length = 120'], capture_output = True, text = True)
issues = {}
for line in result.stdout.split('\n'):
if 'F401' not in line:
continue
parts = line.split(':')
if len(parts) >= 5:
filepath = parts[0]
lineno = int(parts[1])
if filepath not in issues:
issues[filepath] = []
issues[filepath].append((lineno, ':'.join(parts[4:]).strip()))
# Show first file's issues
for filepath in list(issues.keys())[:1]:
print(f'{filepath}:')
for lineno, msg in issues[filepath][:5]:
print(f' Line {lineno}: {msg}')
with open(filepath) as f:
lines = f.readlines()
if lineno <= len(lines):
print(f' Code: {lines[lineno-1].rstrip()}')