|
24 | 24 | import inspect
|
25 | 25 | import importlib
|
26 | 26 | import doctest
|
| 27 | + |
| 28 | +from flake8.api import legacy as flake8 |
| 29 | + |
27 | 30 | try:
|
28 | 31 | from io import StringIO
|
29 | 32 | except ImportError:
|
|
40 | 43 | from numpydoc.docscrape import NumpyDocString
|
41 | 44 | from pandas.io.formats.printing import pprint_thing
|
42 | 45 |
|
43 |
| - |
44 | 46 | PRIVATE_CLASSES = ['NDFrame', 'IndexOpsMixin']
|
45 | 47 | DIRECTIVES = ['versionadded', 'versionchanged', 'deprecated']
|
46 | 48 |
|
@@ -331,6 +333,12 @@ def parameter_mismatches(self):
|
331 | 333 |
|
332 | 334 | return errs
|
333 | 335 |
|
| 336 | + @property |
| 337 | + def pep8_violations(self): |
| 338 | + style_guide = flake8.get_style_guide(doctests=True) |
| 339 | + report = style_guide.input_file(filename=self.source_file_name) |
| 340 | + return report.get_statistics('') |
| 341 | + |
334 | 342 | @property
|
335 | 343 | def correct_parameters(self):
|
336 | 344 | return not bool(self.parameter_mismatches)
|
@@ -446,7 +454,7 @@ def validate_one(func_name):
|
446 | 454 | if doc.summary != doc.summary.lstrip():
|
447 | 455 | errs.append('Summary contains heading whitespaces.')
|
448 | 456 | elif (doc.is_function_or_method
|
449 |
| - and doc.summary.split(' ')[0][-1] == 's'): |
| 457 | + and doc.summary.split(' ')[0][-1] == 's'): |
450 | 458 | errs.append('Summary must start with infinitive verb, '
|
451 | 459 | 'not third person (e.g. use "Generate" instead of '
|
452 | 460 | '"Generates")')
|
@@ -490,6 +498,12 @@ def validate_one(func_name):
|
490 | 498 | for param_err in param_errs:
|
491 | 499 | errs.append('\t{}'.format(param_err))
|
492 | 500 |
|
| 501 | + pep8_errs = doc.pep8_violations |
| 502 | + if pep8_errs: |
| 503 | + errs.append('Errors in doctest sections') |
| 504 | + for pep8_err in pep8_errs: |
| 505 | + errs.append('\t{}'.format(pep8_err)) |
| 506 | + |
493 | 507 | if doc.is_function_or_method:
|
494 | 508 | if not doc.returns and "return" in doc.method_source:
|
495 | 509 | errs.append('No Returns section found')
|
|
0 commit comments