Skip to content

Commit

Permalink
Merge pull request #80 from dihm/blacs-docs
Browse files Browse the repository at this point in the history
Initial pass at BLACS docs
  • Loading branch information
dihm committed Jul 16, 2021
2 parents b083bb8 + 868b991 commit e8bdd1b
Show file tree
Hide file tree
Showing 21 changed files with 699 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -158,4 +158,5 @@ conda_packages/
# Sphinx documentation
docs/html/
docs/source/_build/
docs/source/components.rst
docs/source/components.rst
docs/source/api/_autosummary
2 changes: 2 additions & 0 deletions blacs/__main__.py
Expand Up @@ -10,6 +10,8 @@
# the project for the full license. #
# #
#####################################################################
'''BLACS GUI and supporting code
'''
import labscript_utils.excepthook

import os
Expand Down
32 changes: 32 additions & 0 deletions docs/source/_templates/autosummary-class.rst
@@ -0,0 +1,32 @@
{{ fullname | escape | underline}}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
:members:
:undoc-members:
:show-inheritance:

{% block methods %}
.. automethod:: __init__

{% if methods %}
.. rubric:: {{ _('Methods') }}

.. autosummary::
{% for item in methods %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Attributes') }}

.. autosummary::
{% for item in attributes %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
66 changes: 66 additions & 0 deletions docs/source/_templates/autosummary-module.rst
@@ -0,0 +1,66 @@
{{ fullname | escape | underline}}

.. automodule:: {{ fullname }}

{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Module Attributes') }}

.. autosummary::
:toctree:
{% for item in attributes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block functions %}
{% if functions %}
.. rubric:: {{ _('Functions') }}

.. autosummary::
:toctree:
{% for item in functions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block classes %}
{% if classes %}
.. rubric:: {{ _('Classes') }}

.. autosummary::
:toctree:
:template: autosummary-class.rst
{% for item in classes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block exceptions %}
{% if exceptions %}
.. rubric:: {{ _('Exceptions') }}

.. autosummary::
:toctree:
{% for item in exceptions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block modules %}
{% if modules %}
.. rubric:: Modules

.. autosummary::
:toctree:
:template: autosummary-module.rst
:recursive:
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
18 changes: 18 additions & 0 deletions docs/source/api/index.rst
@@ -0,0 +1,18 @@
API Reference
=============

.. autosummary::
:toctree: _autosummary
:template: autosummary-module.rst
:recursive:

blacs.analysis_submission
blacs.compile_and_restart
blacs.device_base_class
blacs.experiment_queue
blacs.front_panel_settings
blacs.notifications
blacs.output_classes
blacs.plugins
blacs.tab_base_classes
blacs.__main__
62 changes: 62 additions & 0 deletions docs/source/conf.py
Expand Up @@ -10,6 +10,7 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import copy
import os
from pathlib import Path
from m2r import MdInclude
Expand Down Expand Up @@ -39,6 +40,7 @@
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.autosectionlabel",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
Expand All @@ -49,6 +51,26 @@
]

autodoc_typehints = 'description'
autosummary_generate = True
numfig = True
autodoc_mock_imports = ['labscript_utils']

# mock missing site package methods
import site
mock_site_methods = {
# Format:
# method name: return value
'getusersitepackages': '',
'getsitepackages': []
}
__fn = None
for __name, __rval in mock_site_methods.items():
if not hasattr(site, __name):
__fn = lambda *args, __rval=copy.deepcopy(__rval), **kwargs: __rval
setattr(site, __name, __fn)
del __name
del __rval
del __fn

# Prefix each autosectionlabel with the name of the document it is in and a colon
autosectionlabel_prefix_document = True
Expand Down Expand Up @@ -223,3 +245,43 @@ def setup(app):
img_path=img_path
)
)

# hooks to test docstring coverage
app.connect('autodoc-process-docstring', doc_coverage)
app.connect('build-finished', doc_report)


members_to_watch = ['module', 'class', 'function', 'exception', 'method', 'attribute']
doc_count = 0
undoc_count = 0
undoc_objects = []
undoc_print_objects = False


def doc_coverage(app, what, name, obj, options, lines):
global doc_count
global undoc_count
global undoc_objects

if (what in members_to_watch and len(lines) == 0):
# blank docstring detected
undoc_count += 1
undoc_objects.append(name)
else:
doc_count += 1


def doc_report(app, exception):
global doc_count
global undoc_count
global undoc_objects
# print out report of documentation coverage
total_docs = undoc_count + doc_count
if total_docs != 0:
print(f'\nAPI Doc coverage of {doc_count/total_docs:.1%}')
if undoc_print_objects or os.environ.get('READTHEDOCS'):
print('\nItems lacking documentation')
print('===========================')
print(*undoc_objects, sep='\n')
else:
print('No docs counted, run \'make clean\' then rebuild to get the count.')

0 comments on commit e8bdd1b

Please sign in to comment.