Run flake8 on a given file and return the output as a string
(file_path: str)
| 209 | |
| 210 | |
| 211 | def flake8(file_path: str) -> str: |
| 212 | """Run flake8 on a given file and return the output as a string""" |
| 213 | if Path(file_path).suffix != ".py": |
| 214 | return "" |
| 215 | cmd = "flake8 --isolated --select=F821,F822,F831,E111,E112,E113,E999,E902 {file_path}" |
| 216 | # don't use capture_output because it's not compatible with python3.6 |
| 217 | out = subprocess.run(cmd.format(file_path=file_path), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 218 | # Use errors="replace" so non-UTF-8 bytes (e.g. GBK-encoded paths on Windows) don't crash decoding. |
| 219 | return out.stdout.decode("utf-8", errors="replace") |
| 220 | |
| 221 | |
| 222 | class Filemap: |
no test coverage detected