Skip to content

Commit 36e0a3e

Browse files
committed
add sphinx ext to auto gen api docs
1 parent bc12fd7 commit 36e0a3e

28 files changed

+235
-70
lines changed

docs/source/_exts/autogen_api_docs.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from pathlib import Path
2+
3+
from sphinx.application import Sphinx
4+
5+
6+
HERE = Path(__file__).parent
7+
PACKAGE_SRC = HERE.parent.parent.parent / "src"
8+
PUBLIC_API_REFERENCE_FILE = HERE.parent / "api-reference.rst"
9+
PRIVATE_API_REFERENCE_FILE = HERE.parent / "developer-apis.rst"
10+
11+
12+
PUBLIC_TITLE = """API Reference
13+
=============
14+
"""
15+
16+
PRIVATE_TITLE = """Developer APIs
17+
==============
18+
"""
19+
20+
AUTODOC_TEMPLATE = """
21+
.. automodule:: {module}
22+
:members:
23+
"""
24+
25+
26+
def make_autodoc_section(module_name: str) -> str:
27+
return AUTODOC_TEMPLATE.format(module=module_name, underline="-" * len(module_name))
28+
29+
30+
def generate_api_docs():
31+
public_docs = [PUBLIC_TITLE]
32+
private_docs = [PRIVATE_TITLE]
33+
34+
for file in sorted(PACKAGE_SRC.glob("**/*.py")):
35+
if file.stem.startswith("__"):
36+
# skip __init__ and __main__
37+
continue
38+
rel_path = file.relative_to(PACKAGE_SRC)
39+
module_name = ".".join(rel_path.with_suffix("").parts)
40+
api_docs = make_autodoc_section(module_name)
41+
(private_docs if "._" in module_name else public_docs).append(api_docs)
42+
43+
PUBLIC_API_REFERENCE_FILE.write_text("\n".join(public_docs))
44+
PRIVATE_API_REFERENCE_FILE.write_text("\n".join(private_docs))
45+
46+
47+
def setup(app: Sphinx) -> None:
48+
generate_api_docs()
49+
return None
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,98 @@
1-
Package API
2-
===========
1+
API Reference
2+
=============
33

4-
.. module:: idom
54

5+
.. automodule:: idom.cli
6+
:members:
67

7-
Component
8-
---------
98

10-
.. automodule:: idom.core.component
9+
.. automodule:: idom.client.manage
1110
:members:
1211

1312

14-
Hooks
15-
-----
16-
17-
.. automodule:: idom.core.hooks
13+
.. automodule:: idom.client.module
1814
:members:
1915

2016

21-
Layout
22-
------
23-
24-
.. automodule:: idom.core.layout
17+
.. automodule:: idom.config
2518
:members:
2619

2720

28-
Dispatcher
29-
----------
21+
.. automodule:: idom.core.component
22+
:members:
23+
3024

3125
.. automodule:: idom.core.dispatcher
3226
:members:
3327

3428

35-
Server Base
36-
-----------
37-
38-
.. automodule:: idom.server.base
29+
.. automodule:: idom.core.events
3930
:members:
4031

4132

42-
Sanic Servers
43-
-------------
44-
45-
.. automodule:: idom.server.sanic
33+
.. automodule:: idom.core.hooks
4634
:members:
4735

4836

49-
Flask Servers
50-
-------------
51-
52-
.. automodule:: idom.server.flask
37+
.. automodule:: idom.core.layout
5338
:members:
5439

5540

56-
FastAPI Servers
57-
---------------
41+
.. automodule:: idom.core.utils
42+
:members:
5843

59-
.. automodule:: idom.server.fastapi
44+
45+
.. automodule:: idom.core.vdom
6046
:members:
6147

6248

63-
Tornado Servers
64-
---------------
49+
.. automodule:: idom.dialect
50+
:members:
51+
6552

66-
.. automodule:: idom.server.tornado
53+
.. automodule:: idom.log
6754
:members:
6855

6956

70-
HTML Widgets
71-
------------
57+
.. automodule:: idom.server.base
58+
:members:
7259

73-
.. automodule:: idom.widgets.html
60+
61+
.. automodule:: idom.server.fastapi
7462
:members:
75-
:undoc-members:
7663

7764

78-
Widget Tools
79-
------------
65+
.. automodule:: idom.server.flask
66+
:members:
8067

81-
.. automodule:: idom.widgets.utils
68+
69+
.. automodule:: idom.server.prefab
8270
:members:
8371

8472

85-
Dialect
86-
-------
73+
.. automodule:: idom.server.sanic
74+
:members:
75+
8776

88-
.. automodule:: idom.dialect
77+
.. automodule:: idom.server.tornado
8978
:members:
9079

9180

92-
Client
93-
------
81+
.. automodule:: idom.server.utils
82+
:members:
9483

95-
.. automodule:: idom.client.module
84+
85+
.. automodule:: idom.testing
9686
:members:
9787

98-
.. automodule:: idom.client.manage
88+
89+
.. automodule:: idom.utils
9990
:members:
10091

10192

102-
Useful Tools
103-
------------
93+
.. automodule:: idom.widgets.html
94+
:members:
95+
10496

105-
.. automodule:: idom.utils
97+
.. automodule:: idom.widgets.utils
10698
:members:

docs/source/conf.py

+10
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@
5353
"sphinx.ext.napoleon",
5454
"sphinx.ext.extlinks",
5555
"sphinx.ext.autosectionlabel",
56+
# third party extensions
5657
"sphinx_autodoc_typehints",
5758
"sphinx_panels",
5859
"sphinx_copybutton",
60+
"sphinx_reredirects",
5961
# custom extensions
6062
"async_doctest",
63+
"autogen_api_docs",
6164
"copy_vdom_json_schema",
6265
"interactive_widget",
6366
"patched_html_translator",
@@ -113,6 +116,13 @@
113116
# order autodoc members by their order in the source
114117
autodoc_member_order = "bysource"
115118

119+
# -- sphinx_reredirects --
120+
121+
redirects = {
122+
"package-api": "api-reference.html",
123+
"configuration-options": "api-reference.html#configuration-options",
124+
}
125+
116126
# -- Options for HTML output -------------------------------------------------
117127

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

docs/source/configuration-options.rst

-12
This file was deleted.

docs/source/developer-apis.rst

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Developer APIs
2+
==============
3+
4+
5+
.. automodule:: idom._option
6+
:members:
7+
8+
9+
.. automodule:: idom.client._private
10+
:members:

docs/source/index.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Libraries for defining and controlling interactive webpages with Python
1010
installation
1111
getting-started
1212
life-cycle-hooks
13-
package-api
13+
api-reference
1414
examples
1515

1616
.. toctree::
@@ -20,7 +20,6 @@ Libraries for defining and controlling interactive webpages with Python
2020
core-concepts
2121
javascript-components
2222
command-line
23-
configuration-options
2423
specifications
2524

2625
.. toctree::
@@ -29,6 +28,7 @@ Libraries for defining and controlling interactive webpages with Python
2928

3029
contributing
3130
developer-guide
31+
developer-apis
3232
changelog
3333
roadmap
3434

requirements/build-docs.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ sphinx-panels ==0.5.0
55
setuptools_scm
66
sphinx-copybutton ==0.3.0
77
sphinx-autobuild ==2020.9.1
8+
sphinx-reredirects ==0.0.1

src/idom/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"Import",
5454
"hotswap",
5555
"multiview",
56-
"JupyterDisplay",
5756
"html_to_vdom",
5857
"VdomDict",
5958
"widgets",

src/idom/client/manage.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Client Manager
3+
==============
4+
"""
5+
16
import shutil
27
import subprocess
38
from logging import getLogger
@@ -49,6 +54,7 @@ def web_module_exists(package_name: str) -> bool:
4954

5055

5156
def web_module_names() -> Set[str]:
57+
"""Get the names of all installed web modules"""
5258
names = []
5359
web_mod_dir = _private.web_modules_dir()
5460
for pth in web_mod_dir.glob("**/*.js"):
@@ -63,6 +69,7 @@ def web_module_names() -> Set[str]:
6369

6470

6571
def add_web_module(package_name: str, source: Union[Path, str]) -> str:
72+
"""Add a web module from source"""
6673
source = Path(source)
6774
if not source.exists():
6875
raise FileNotFoundError(f"Package source file does not exist: {str(source)!r}")
@@ -81,6 +88,7 @@ def build(
8188
clean_build: bool = True,
8289
skip_if_already_installed: bool = True,
8390
) -> None:
91+
"""Build the client"""
8492
package_specifiers_to_install = list(packages)
8593
del packages # delete since we just renamed it
8694

src/idom/client/module.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Client Modules
3+
==============
4+
"""
5+
16
from __future__ import annotations
27

38
from pathlib import Path

src/idom/config.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""
2+
Configuration Options
3+
=====================
4+
5+
IDOM provides a series of configuration options that can be set using environment
6+
variables or, for those which allow it, a programatic interface.
7+
"""
8+
19
from pathlib import Path
210
from typing import cast
311

src/idom/core/component.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Component
3+
=========
4+
"""
5+
16
from __future__ import annotations
27

38
import abc
@@ -17,8 +22,7 @@ def component(function: ComponentRenderFunction) -> Callable[..., "Component"]:
1722
"""A decorator for defining an :class:`Component`.
1823
1924
Parameters:
20-
function:
21-
The function that will render a :ref:`VDOM <VDOM Mimetype>` model.
25+
function: The function that will render a :class:`VdomDict`.
2226
"""
2327

2428
@wraps(function)
@@ -38,7 +42,7 @@ class AbstractComponent(abc.ABC):
3842

3943
@abc.abstractmethod
4044
def render(self) -> VdomDict:
41-
"""Render the component's :ref:`VDOM <VDOM Mimetype>` model."""
45+
"""Render the component's :class:`VdomDict`."""
4246

4347

4448
class Component(AbstractComponent):

src/idom/core/dispatcher.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Dispatchers
3+
===========
4+
"""
5+
16
from __future__ import annotations
27

38
import sys

src/idom/core/events.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Events
3+
"""
4+
15
import asyncio
26
from typing import (
37
Any,

src/idom/core/hooks.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Hooks
3+
=====
4+
"""
5+
16
from __future__ import annotations
27

38
import asyncio

0 commit comments

Comments
 (0)