Skip to content

Commit d412be3

Browse files
committed
Add docstring coverage check to build.
1 parent 1b0a4f5 commit d412be3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

docs/source/conf.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,43 @@ def setup(app):
243243
img_path=img_path
244244
)
245245
)
246+
247+
# hooks to test docstring coverage
248+
app.connect('autodoc-process-docstring', doc_coverage)
249+
app.connect('build-finished', doc_report)
250+
251+
252+
members_to_watch = ['module', 'class', 'function', 'exception', 'method', 'attribute']
253+
doc_count = 0
254+
undoc_count = 0
255+
undoc_objects = []
256+
undoc_print_objects = False
257+
258+
259+
def doc_coverage(app, what, name, obj, options, lines):
260+
global doc_count
261+
global undoc_count
262+
global undoc_objects
263+
264+
if (what in members_to_watch and len(lines) == 0):
265+
# blank docstring detected
266+
undoc_count += 1
267+
undoc_objects.append(name)
268+
else:
269+
doc_count += 1
270+
271+
272+
def doc_report(app, exception):
273+
global doc_count
274+
global undoc_count
275+
global undoc_objects
276+
# print out report of documentation coverage
277+
total_docs = undoc_count + doc_count
278+
if total_docs != 0:
279+
print(f'\nAPI Doc coverage of {doc_count/total_docs:.1%}')
280+
if undoc_print_objects or os.environ.get('READTHEDOCS'):
281+
print('\nItems lacking documentation')
282+
print('===========================')
283+
print(*undoc_objects, sep='\n')
284+
else:
285+
print('No docs counted, run \'make clean\' then rebuild to get the count.')

0 commit comments

Comments
 (0)