Skip to content

Commit 5aa43cd

Browse files
authored
DOC: Auto-generate full API docs (#1505)
* DOC: Use auto-summary to generate full API docs Use custom template to prevent every class and function from getting its own page. * MNT: Ignore generated API docs * DOC: Update docstrings due to sphinx complaints * DOC: Add intersphinx
1 parent 19e6c4a commit 5aa43cd

File tree

9 files changed

+108
-61
lines changed

9 files changed

+108
-61
lines changed

tools/schemacode/bidsschematools/tests/test_make_testdata.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ def test_make_archive(bids_examples, bids_error_examples):
2424
2525
Notes
2626
-----
27-
* Due to intricacies arising from:
28-
(1) fixtures not working outside of pytest
29-
(2) implicit teardown leveraging tempdata removal (while held open by yield)
30-
(3) wrappers evaluating the yield statement
31-
(4) the desire to not download testdata twice for archive creation
32-
testdata archive creation is now inconspicuously posing as a test.
27+
Due to intricacies arising from:
28+
29+
(1) fixtures not working outside of pytest
30+
(2) implicit teardown leveraging tempdata removal (while held open by yield)
31+
(3) wrappers evaluating the yield statement
32+
(4) the desire to not download testdata twice for archive creation
33+
34+
testdata archive creation is now inconspicuously posing as a test.
3335
"""
3436

3537
testdata_dir = files("bidsschematools.tests.data")

tools/schemacode/bidsschematools/tests/test_render_text.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ def test_make_glossary(schema_obj, schema_dir):
6767
def test_make_filename_template(schema_obj, schema_dir):
6868
"""
6969
Test whether:
70-
* the base hierarchy structure of mandatory subject and optional session is
71-
returned. This should be robust with respect to schema format.
72-
* each directory contains at least one possible pattern.
73-
This should be robust with respect to schema format.
74-
* all files under the datatype rules subdirectory have corresponding entries.
75-
This may need to be updated for schema hierarchy changes.
70+
71+
* The base hierarchy structure of mandatory subject and optional session is
72+
returned. This should be robust with respect to schema format.
73+
* Each directory contains at least one possible pattern.
74+
This should be robust with respect to schema format.
75+
* All files under the datatype rules subdirectory have corresponding entries.
76+
This may need to be updated for schema hierarchy changes.
7677
"""
7778
filename_template = text.make_filename_template("raw", schema_obj, pdf_format=True)
7879

tools/schemacode/docs/.gitignore

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

tools/schemacode/docs/api.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Schema Tools API
2+
================
3+
4+
.. autosummary::
5+
:toctree: api
6+
:template: module.rst
7+
:recursive:
8+
9+
bidsschematools

tools/schemacode/docs/bidsschematools.rst

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

tools/schemacode/docs/conf.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@
3030
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3131
# ones.
3232
extensions = [
33+
"sphinx.ext.intersphinx",
3334
"sphinx.ext.duration",
3435
"sphinx.ext.doctest",
3536
"sphinx.ext.coverage",
3637
"sphinx.ext.napoleon",
38+
"sphinx.ext.autodoc",
39+
"sphinx.ext.autosummary",
3740
"myst_parser",
3841
]
3942

43+
autosummary_generate = True
44+
4045
# Add any paths that contain templates here, relative to this directory.
4146
templates_path = ["_templates"]
4247

@@ -46,6 +51,14 @@
4651
exclude_patterns = ["_build", "tests"]
4752

4853

54+
# Mock internal modules to avoid building docs
55+
autosummary_mock_imports = [
56+
"bidsschematools.conftest",
57+
]
58+
59+
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
60+
61+
4962
# -- Options for HTML output -------------------------------------------------
5063

5164
# The theme to use for HTML and HTML Help pages. See the documentation for

tools/schemacode/docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ Contents
55
========
66

77
.. toctree::
8-
modules
98
:maxdepth: 2
109

10+
api
11+
1112

1213
Indices and tables
1314
==================

tools/schemacode/docs/modules.rst

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

0 commit comments

Comments
 (0)