Skip to content

Commit 04db899

Browse files
authored
Merge pull request #74 from dihm/labscript-docs
Initial pass at API docs for labscript
2 parents a805b69 + 9915e50 commit 04db899

16 files changed

+1301
-206
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ instance/
7777

7878
# Sphinx documentation
7979
docs/_build/
80+
docs/source/api/_autosummary/
8081

8182
# PyBuilder
8283
.pybuilder/
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{ fullname | escape | underline}}
2+
3+
.. currentmodule:: {{ module }}
4+
5+
.. autoclass:: {{ objname }}
6+
:members:
7+
:undoc-members:
8+
:show-inheritance:
9+
10+
{% block methods %}
11+
.. automethod:: __init__
12+
13+
{% if methods %}
14+
.. rubric:: {{ _('Methods') }}
15+
16+
.. autosummary::
17+
{% for item in methods %}
18+
~{{ name }}.{{ item }}
19+
{%- endfor %}
20+
{% endif %}
21+
{% endblock %}
22+
23+
{% block attributes %}
24+
{% if attributes %}
25+
.. rubric:: {{ _('Attributes') }}
26+
27+
.. autosummary::
28+
{% for item in attributes %}
29+
~{{ name }}.{{ item }}
30+
{%- endfor %}
31+
{% endif %}
32+
{% endblock %}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{{ fullname | escape | underline}}
2+
3+
.. automodule:: {{ fullname }}
4+
5+
{% block attributes %}
6+
{% if attributes %}
7+
.. rubric:: {{ _('Module Attributes') }}
8+
9+
.. autosummary::
10+
:toctree:
11+
{% for item in attributes %}
12+
{{ item }}
13+
{%- endfor %}
14+
{% endif %}
15+
{% endblock %}
16+
17+
{% block functions %}
18+
{% if functions %}
19+
.. rubric:: {{ _('Functions') }}
20+
21+
.. autosummary::
22+
:toctree:
23+
{% for item in functions %}
24+
{{ item }}
25+
{%- endfor %}
26+
{% endif %}
27+
{% endblock %}
28+
29+
{% block classes %}
30+
{% if classes %}
31+
.. rubric:: {{ _('Classes') }}
32+
33+
.. autosummary::
34+
:toctree:
35+
:template: autosummary-class.rst
36+
{% for item in classes %}
37+
{{ item }}
38+
{%- endfor %}
39+
{% endif %}
40+
{% endblock %}
41+
42+
{% block exceptions %}
43+
{% if exceptions %}
44+
.. rubric:: {{ _('Exceptions') }}
45+
46+
.. autosummary::
47+
:toctree:
48+
{% for item in exceptions %}
49+
{{ item }}
50+
{%- endfor %}
51+
{% endif %}
52+
{% endblock %}
53+
54+
{% block modules %}
55+
{% if modules %}
56+
.. rubric:: Modules
57+
58+
.. autosummary::
59+
:toctree:
60+
:template: autosummary-module.rst
61+
:recursive:
62+
{% for item in modules %}
63+
{{ item }}
64+
{%- endfor %}
65+
{% endif %}
66+
{% endblock %}

docs/source/api/clockline.rst

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/source/api/device.rst

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/source/api/index.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
API Reference
33
=============
44

5-
.. toctree::
6-
:maxdepth: 2
7-
8-
device
9-
pseudoclockdevice
10-
pseudoclock
11-
clockline
12-
intermediatedevice
13-
5+
.. autosummary::
6+
:toctree: _autosummary
7+
:template: autosummary-module.rst
8+
:recursive:
149

10+
labscript.labscript
11+
labscript.functions

docs/source/api/intermediatedevice.rst

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/source/api/pseudoclock.rst

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/source/api/pseudoclockdevice.rst

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/source/conf.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# ones.
3939
extensions = [
4040
"sphinx.ext.autodoc",
41+
"sphinx.ext.autosummary",
4142
"sphinx.ext.autosectionlabel",
4243
"sphinx.ext.intersphinx",
4344
"sphinx.ext.napoleon",
@@ -48,6 +49,8 @@
4849
]
4950

5051
autodoc_typehints = 'description'
52+
autosummary_generate = True
53+
add_module_names = False
5154

5255
# Prefix each autosectionlabel with the name of the document it is in and a colon
5356
autosectionlabel_prefix_document = True
@@ -222,3 +225,42 @@ def setup(app):
222225
img_path=img_path
223226
)
224227
)
228+
229+
app.connect('autodoc-process-docstring', doc_coverage)
230+
app.connect('build-finished', doc_report)
231+
232+
233+
members_to_watch = ['module', 'class', 'function', 'exception', 'method', 'attribute']
234+
doc_count = 0
235+
undoc_count = 0
236+
undoc_objects = []
237+
undoc_print_objects = False
238+
239+
240+
def doc_coverage(app, what, name, obj, options, lines):
241+
global doc_count
242+
global undoc_count
243+
global undoc_objects
244+
245+
if (what in members_to_watch and len(lines) == 0):
246+
# blank docstring detected
247+
undoc_count += 1
248+
undoc_objects.append(name)
249+
else:
250+
doc_count += 1
251+
252+
253+
def doc_report(app, exception):
254+
global doc_count
255+
global undoc_count
256+
global undoc_objects
257+
# print out report of documentation coverage
258+
total_docs = undoc_count + doc_count
259+
if total_docs != 0:
260+
print(f'\nAPI Doc coverage of {doc_count/total_docs:.1%}')
261+
if undoc_print_objects or os.environ.get('READTHEDOCS'):
262+
print('\nItems lacking documentation')
263+
print('===========================')
264+
print(*undoc_objects, sep='\n')
265+
else:
266+
print('No docs counted, run \'make clean\' then rebuild to get the count.')

0 commit comments

Comments
 (0)