|
19 | 19 | import importlib
|
20 | 20 | import json
|
21 | 21 | import os
|
| 22 | +import subprocess |
22 | 23 | import sys
|
23 | 24 | import tempfile
|
24 | 25 | from typing import (
|
25 | 26 | List,
|
26 | 27 | Optional,
|
27 | 28 | )
|
28 | 29 |
|
29 |
| -import flake8.main.application |
30 |
| - |
31 | 30 | try:
|
32 | 31 | from io import StringIO
|
33 | 32 | except ImportError:
|
@@ -183,20 +182,21 @@ def validate_pep8(self):
|
183 | 182 | )
|
184 | 183 | )
|
185 | 184 |
|
186 |
| - application = flake8.main.application.Application() |
187 |
| - application.initialize(["--quiet"]) |
188 |
| - |
| 185 | + error_messages = [] |
189 | 186 | with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8") as file:
|
190 | 187 | file.write(content)
|
191 | 188 | file.flush()
|
192 |
| - application.run_checks([file.name]) |
| 189 | + cmd = ["python", "-m", "flake8", "--quiet", "--statistics", file.name] |
| 190 | + response = subprocess.run(cmd, capture_output=True, text=True) |
| 191 | + stdout = response.stdout |
| 192 | + stdout = stdout.replace(file.name, "") |
| 193 | + messages = stdout.strip("\n") |
| 194 | + if messages: |
| 195 | + error_messages.append(messages) |
193 | 196 |
|
194 |
| - # We need this to avoid flake8 printing the names of the files to |
195 |
| - # the standard output |
196 |
| - application.formatter.write = lambda line, source: None |
197 |
| - application.report() |
198 |
| - |
199 |
| - yield from application.guide.stats.statistics_for("") |
| 197 | + for error_message in error_messages: |
| 198 | + error_count, error_code, message = error_message.split(maxsplit=2) |
| 199 | + yield error_code, message, int(error_count) |
200 | 200 |
|
201 | 201 |
|
202 | 202 | def pandas_validate(func_name: str):
|
@@ -240,13 +240,15 @@ def pandas_validate(func_name: str):
|
240 | 240 | result["errors"].append(
|
241 | 241 | pandas_error("EX02", doctest_log=result["examples_errs"])
|
242 | 242 | )
|
243 |
| - for err in doc.validate_pep8(): |
| 243 | + |
| 244 | + for error_code, error_message, error_count in doc.validate_pep8(): |
| 245 | + times_happening = f" ({error_count} times)" if error_count > 1 else "" |
244 | 246 | result["errors"].append(
|
245 | 247 | pandas_error(
|
246 | 248 | "EX03",
|
247 |
| - error_code=err.error_code, |
248 |
| - error_message=err.message, |
249 |
| - times_happening=f" ({err.count} times)" if err.count > 1 else "", |
| 249 | + error_code=error_code, |
| 250 | + error_message=error_message, |
| 251 | + times_happening=times_happening, |
250 | 252 | )
|
251 | 253 | )
|
252 | 254 | examples_source_code = "".join(doc.examples_source_code)
|
|
0 commit comments