|
58 | 58 | "SA05": "{reference_name} in `See Also` section does not need `pandas` "
|
59 | 59 | "prefix, use {right_reference} instead.",
|
60 | 60 | "EX02": "Examples do not pass tests:\n{doctest_log}",
|
61 |
| - "EX03": "flake8 error: {error_code} {error_message}{times_happening}", |
| 61 | + "EX03": "flake8 error: line {line_number}, col {col_number}: {error_code} " |
| 62 | + "{error_message}", |
62 | 63 | "EX04": "Do not import {imported_library}, as it is imported "
|
63 | 64 | "automatically for the examples (numpy as np, pandas as pd)",
|
64 | 65 | }
|
@@ -212,20 +213,31 @@ def validate_pep8(self):
|
212 | 213 | try:
|
213 | 214 | file.write(content)
|
214 | 215 | file.flush()
|
215 |
| - cmd = ["python", "-m", "flake8", "--quiet", "--statistics", file.name] |
| 216 | + cmd = [ |
| 217 | + "python", |
| 218 | + "-m", |
| 219 | + "flake8", |
| 220 | + "--format=%(row)d\t%(col)d\t%(code)s\t%(text)s", |
| 221 | + file.name, |
| 222 | + ] |
216 | 223 | response = subprocess.run(cmd, capture_output=True, check=False, text=True)
|
217 | 224 | stdout = response.stdout
|
218 | 225 | stdout = stdout.replace(file.name, "")
|
219 |
| - messages = stdout.strip("\n") |
| 226 | + messages = stdout.strip("\n").splitlines() |
220 | 227 | if messages:
|
221 |
| - error_messages.append(messages) |
| 228 | + error_messages.extend(messages) |
222 | 229 | finally:
|
223 | 230 | file.close()
|
224 | 231 | os.unlink(file.name)
|
225 | 232 |
|
226 | 233 | for error_message in error_messages:
|
227 |
| - error_count, error_code, message = error_message.split(maxsplit=2) |
228 |
| - yield error_code, message, int(error_count) |
| 234 | + line_number, col_number, error_code, message = error_message.split( |
| 235 | + "\t", maxsplit=3 |
| 236 | + ) |
| 237 | + # Note: we subtract 2 from the line number because |
| 238 | + # 'import numpy as np\nimport pandas as pd\n' |
| 239 | + # is prepended to the docstrings. |
| 240 | + yield error_code, message, int(line_number) - 2, int(col_number) |
229 | 241 |
|
230 | 242 | def non_hyphenated_array_like(self):
|
231 | 243 | return "array_like" in self.raw_doc
|
@@ -276,14 +288,14 @@ def pandas_validate(func_name: str):
|
276 | 288 | pandas_error("EX02", doctest_log=result["examples_errs"])
|
277 | 289 | )
|
278 | 290 |
|
279 |
| - for error_code, error_message, error_count in doc.validate_pep8(): |
280 |
| - times_happening = f" ({error_count} times)" if error_count > 1 else "" |
| 291 | + for error_code, error_message, line_number, col_number in doc.validate_pep8(): |
281 | 292 | result["errors"].append(
|
282 | 293 | pandas_error(
|
283 | 294 | "EX03",
|
284 | 295 | error_code=error_code,
|
285 | 296 | error_message=error_message,
|
286 |
| - times_happening=times_happening, |
| 297 | + line_number=line_number, |
| 298 | + col_number=col_number, |
287 | 299 | )
|
288 | 300 | )
|
289 | 301 | examples_source_code = "".join(doc.examples_source_code)
|
@@ -407,7 +419,7 @@ def header(title, width=80, char="#"):
|
407 | 419 |
|
408 | 420 | sys.stderr.write(header("Validation"))
|
409 | 421 | if result["errors"]:
|
410 |
| - sys.stderr.write(f'{len(result["errors"])} Errors found:\n') |
| 422 | + sys.stderr.write(f'{len(result["errors"])} Errors found for `{func_name}`:\n') |
411 | 423 | for err_code, err_desc in result["errors"]:
|
412 | 424 | if err_code == "EX02": # Failing examples are printed at the end
|
413 | 425 | sys.stderr.write("\tExamples do not pass tests\n")
|
|
0 commit comments