Skip to content

Commit c87360d

Browse files
committed
[skip ci] Integrate flake8 into validate_docstrings.py
Signed-off-by: Fabian Haase <[email protected]>
1 parent b9e2278 commit c87360d

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

scripts/validate_docstrings.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import inspect
2525
import importlib
2626
import doctest
27+
28+
from flake8.api import legacy as flake8
29+
2730
try:
2831
from io import StringIO
2932
except ImportError:
@@ -40,7 +43,6 @@
4043
from numpydoc.docscrape import NumpyDocString
4144
from pandas.io.formats.printing import pprint_thing
4245

43-
4446
PRIVATE_CLASSES = ['NDFrame', 'IndexOpsMixin']
4547
DIRECTIVES = ['versionadded', 'versionchanged', 'deprecated']
4648

@@ -331,6 +333,12 @@ def parameter_mismatches(self):
331333

332334
return errs
333335

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+
334342
@property
335343
def correct_parameters(self):
336344
return not bool(self.parameter_mismatches)
@@ -446,7 +454,7 @@ def validate_one(func_name):
446454
if doc.summary != doc.summary.lstrip():
447455
errs.append('Summary contains heading whitespaces.')
448456
elif (doc.is_function_or_method
449-
and doc.summary.split(' ')[0][-1] == 's'):
457+
and doc.summary.split(' ')[0][-1] == 's'):
450458
errs.append('Summary must start with infinitive verb, '
451459
'not third person (e.g. use "Generate" instead of '
452460
'"Generates")')
@@ -490,6 +498,12 @@ def validate_one(func_name):
490498
for param_err in param_errs:
491499
errs.append('\t{}'.format(param_err))
492500

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+
493507
if doc.is_function_or_method:
494508
if not doc.returns and "return" in doc.method_source:
495509
errs.append('No Returns section found')

setup.cfg

+25
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ exclude =
2828
doc/temp/*.py,
2929
.eggs/*.py,
3030
versioneer.py
31+
.tox
32+
.git
33+
34+
doctests = True
35+
#TODO fix doctests
36+
exclude_from_doctest =
37+
./pandas/_libs
38+
./pandas/api
39+
./pandas/compat
40+
./pandas/computation
41+
./pandas/core
42+
./pandas/errors
43+
./pandas/io
44+
./pandas/plotting
45+
./pandas/tests
46+
./pandas/tools
47+
./pandas/tseries
48+
./pandas/types
49+
./pandas/util
50+
51+
[flake8-rst]
52+
ignore =
53+
F821, # undefined name
54+
W391, # blank line at end of file [Seems to be a bug (v0.4.1)]
55+
3156

3257
[yapf]
3358
based_on_style = pep8

0 commit comments

Comments
 (0)