Skip to content

Commit 461dc9f

Browse files
committed
Add docstring coverage test to build.
1 parent f90a4cc commit 461dc9f

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

0 commit comments

Comments
 (0)