Skip to content

Commit da5218f

Browse files
committed
misc doc improvements
1 parent 1a581eb commit da5218f

14 files changed

+94
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from docutils import nodes
2+
from sphinx import addnodes
3+
from sphinx.application import Sphinx
4+
from sphinx.transforms.post_transforms import SphinxPostTransform
5+
from sphinx.util import logging
6+
7+
8+
logger = logging.getLogger(__name__)
9+
10+
11+
def is_public_internal_ref_target(target: str) -> bool:
12+
return target.startswith("idom.") and not target.rsplit(".", 1)[-1].startswith("_")
13+
14+
15+
class OnlyWarnOnBrokenInternalRefs(SphinxPostTransform):
16+
"""
17+
Warns about broken cross-reference links, but only for idom.
18+
This is very similar to the sphinx option ``nitpicky=True`` (see
19+
:py:class:`sphinx.transforms.post_transforms.ReferencesResolver`), but there
20+
is no way to restrict that option to a specific package.
21+
"""
22+
23+
# this transform needs to happen before ReferencesResolver
24+
default_priority = 5
25+
26+
def run(self) -> None:
27+
for node in self.document.traverse(addnodes.pending_xref):
28+
target = node["reftarget"]
29+
30+
if is_public_internal_ref_target(target):
31+
# let the domain try to resolve the reference
32+
found_ref = self.env.domains[node["refdomain"]].resolve_xref(
33+
self.env,
34+
node.get("refdoc", self.env.docname),
35+
self.app.builder,
36+
node["reftype"],
37+
target,
38+
node,
39+
nodes.TextElement("", ""),
40+
)
41+
42+
# warn if resolve_xref did not return or raised
43+
if not found_ref:
44+
logger.warning(
45+
f"API link {target} is broken.", location=node, type="ref"
46+
)
47+
48+
49+
def setup(app: Sphinx) -> None:
50+
app.add_post_transform(OnlyWarnOnBrokenInternalRefs)

docs/source/architectural-patterns.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ As a result, IDOM was developed to help solve these problems.
5757
Ecosystem Independence
5858
----------------------
5959

60-
IDOM has a flexible set of :ref:`core abstractions <Core Concepts>` that allow it to
61-
interface with its peers. At the time of writing Jupyter, Dash, and Bokeh (via Panel)
62-
are supported, while Streamlit is in the works:
60+
IDOM has a flexible set of :ref:`Core Abstractions` that allow it to interface with its
61+
peers. At the time of writing Jupyter, Dash, and Bokeh (via Panel) are supported, while
62+
Streamlit is in the works:
6363

6464
- idom-jupyter_ (try it now with Binder_)
6565
- idom-dash_

docs/source/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"patched_html_translator",
6666
"widget_example",
6767
"build_custom_js",
68+
"only_warn_on_broken_internal_refs",
6869
]
6970

7071
# Add any paths that contain templates here, relative to this directory.

docs/source/core-concepts.rst renamed to docs/source/core-abstractions.rst

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
Core Concepts
2-
=============
3-
4-
This section covers core features of IDOM that are used in making interactive
5-
interfaces.
1+
Core Abstractions
2+
=================
63

74

85
Pure Components

docs/source/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ IDOM
1515
:hidden:
1616
:caption: Advanced Topics
1717

18-
core-concepts
18+
core-abstractions
1919
javascript-components
2020
architectural-patterns
2121
specifications

docs/source/life-cycle-hooks.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,9 @@ use_ref
284284
285285
ref_container = use_ref(initial_value)
286286
287-
Returns a mutable :class:`~idom.core.hooks.Ref` object that has a single
288-
:attr:`~idom.core.hooks.Ref.current` attribute that at first contains the
289-
``initial_state``. The identity of the ``Ref`` object will be preserved for the lifetime
290-
of the component.
287+
Returns a mutable :class:`~idom.utils.Ref` object that has a single
288+
:attr:`~idom.utils.Ref.current` attribute that at first contains the ``initial_state``.
289+
The identity of the ``Ref`` object will be preserved for the lifetime of the component.
291290

292291
A ``Ref`` is most useful if you need to incur side effects since updating its
293292
``.current`` attribute doesn't trigger a re-render of the component. You'll often use this

docs/source/roadmap.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Roadmap
3434
they need purpose-built
3535
`compiler plugins <https://github.com/idom-team/idom-react-component-cookiecutter/blob/1cc31b8690f84cb90dd861f2f47873b1d5711f74/%7B%7Bcookiecutter.repository_name%7D%7D/js/rollup.config.js>`__
3636
that will convert imports of React to point to the location ``react.js`` will be
37-
once the component has been loaded via :class:`~idom.client.module.Module`.
37+
once the component has been loaded via ``idom.client.module.Module``
3838

3939
Ideally developers of custom components should be able to operate in isolation
4040
without assuming anything about the environment they are running in. This has the

noxfile.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,18 @@ def test_docs(session: Session) -> None:
161161
"""Verify that the docs build and that doctests pass"""
162162
install_requirements_file(session, "build-docs")
163163
install_idom_dev(session, extras="all")
164-
session.run("sphinx-build", "-T", "-b", "html", "docs/source", "docs/build")
165-
session.run("sphinx-build", "-T", "-b", "doctest", "docs/source", "docs/build")
164+
session.run(
165+
"sphinx-build",
166+
"-a", # re-write all output files
167+
"-T", # show full tracebacks
168+
"-W", # turn warnings into errors
169+
"--keep-going", # complete the build, but still report warnings as errors
170+
"-b",
171+
"html",
172+
"docs/source",
173+
"docs/build",
174+
)
175+
session.run("sphinx-build", "-b", "doctest", "docs/source", "docs/build")
166176

167177

168178
@nox.session

src/idom/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"""The location IDOM will use to store its client application
3939
4040
This directory **MUST** be treated as a black box. Downstream applications **MUST NOT**
41-
assume anything about the structure of this directory see :mod:`idom.client.manage` for
42-
a set of publically available APIs for working with the client.
41+
assume anything about the structure of this directory see :mod:`idom.web.module` for a
42+
set of publically available APIs for working with the client.
4343
"""
4444

4545
IDOM_FEATURE_INDEX_AS_DEFAULT_KEY = _Option(

src/idom/core/dispatcher.py

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ async def dispatch_single_view(
3636
send: SendCoroutine,
3737
recv: RecvCoroutine,
3838
) -> None:
39+
"""Run a dispatch loop for a single view instance"""
3940
with layout:
4041
async with create_task_group() as task_group:
4142
task_group.start_soon(_single_outgoing_loop, layout, send)
@@ -50,6 +51,7 @@ async def dispatch_single_view(
5051
async def create_shared_view_dispatcher(
5152
layout: Layout, run_forever: bool = False
5253
) -> AsyncIterator[_SharedViewDispatcherFuture]:
54+
"""Enter a dispatch context where all subsequent view instances share the same state"""
5355
with layout:
5456
(
5557
dispatch_shared_view,
@@ -94,6 +96,7 @@ def dispatch_shared_view_soon(
9496
def ensure_shared_view_dispatcher_future(
9597
layout: Layout,
9698
) -> Tuple[Future[None], SharedViewDispatcher]:
99+
"""Ensure the future of a dispatcher created by :func:`create_shared_view_dispatcher`"""
97100
dispatcher_future: Future[SharedViewDispatcher] = Future()
98101

99102
async def dispatch_shared_view_forever() -> None:

src/idom/core/layout.py

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class LayoutEvent(NamedTuple):
5555

5656

5757
class Layout:
58+
"""Responsible for "rendering" components. That is, turning them into VDOM."""
5859

5960
__slots__ = [
6061
"root",
@@ -94,10 +95,12 @@ def __exit__(self, *exc: Any) -> None:
9495
return None
9596

9697
def update(self, component: "AbstractComponent") -> None:
98+
"""Schedule a re-render of a component in the layout"""
9799
self._rendering_queue.put(component)
98100
return None
99101

100102
async def dispatch(self, event: LayoutEvent) -> None:
103+
"""Dispatch an event to the targeted handler"""
101104
# It is possible for an element in the frontend to produce an event
102105
# associated with a backend model that has been deleted. We only handle
103106
# events if the element and the handler exist in the backend. Otherwise
@@ -115,6 +118,7 @@ async def dispatch(self, event: LayoutEvent) -> None:
115118
)
116119

117120
async def render(self) -> LayoutUpdate:
121+
"""Await the next available render. This will block until a component is updated"""
118122
while True:
119123
component = await self._rendering_queue.get()
120124
if id(component) in self._model_state_by_component_id:

src/idom/server/prefab.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def multiview_server(
8080
) -> Tuple[MultiViewMount, Server[_App]]:
8181
"""Set up a server where views can be dynamically added.
8282
83-
In other words this allows the user to work with IDOM in an imperative manner.
84-
Under the hood this uses the :func:`idom.widgets.common.multiview` function to
85-
add the views on the fly.
83+
In other words this allows the user to work with IDOM in an imperative manner. Under
84+
the hood this uses the :func:`idom.widgets.multiview` function to add the views on
85+
the fly.
8686
8787
Parameters:
8888
server: The server type to start up as a daemon
@@ -93,8 +93,8 @@ def multiview_server(
9393
app: Optionally provide a prexisting application to register to
9494
9595
Returns:
96-
The server instance and a function for adding views.
97-
See :func:`idom.widgets.common.multiview` for details.
96+
The server instance and a function for adding views. See
97+
:func:`idom.widgets.multiview` for details.
9898
"""
9999
mount, component = multiview()
100100

@@ -123,9 +123,9 @@ def hotswap_server(
123123
) -> Tuple[MountFunc, Server[_App]]:
124124
"""Set up a server where views can be dynamically swapped out.
125125
126-
In other words this allows the user to work with IDOM in an imperative manner.
127-
Under the hood this uses the :func:`idom.widgets.common.hotswap` function to
128-
swap the views on the fly.
126+
In other words this allows the user to work with IDOM in an imperative manner. Under
127+
the hood this uses the :func:`idom.widgets.hotswap` function to swap the views on
128+
the fly.
129129
130130
Parameters:
131131
server: The server type to start up as a daemon
@@ -137,8 +137,8 @@ def hotswap_server(
137137
sync_views: Whether to update all displays with newly mounted components
138138
139139
Returns:
140-
The server instance and a function for swapping views.
141-
See :func:`idom.widgets.common.hotswap` for details.
140+
The server instance and a function for swapping views. See
141+
:func:`idom.widgets.hotswap` for details.
142142
"""
143143
mount, component = hotswap(update_on_change=sync_views)
144144

src/idom/utils.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class Ref(Generic[_RefValue]):
1717
incur side effects. Generally refs should be avoided if possible, but sometimes
1818
they are required.
1919
20-
Attributes:
21-
current: The present value.
22-
2320
Notes:
2421
You can compare the contents for two ``Ref`` objects using the ``==`` operator.
2522
"""
@@ -28,6 +25,7 @@ class Ref(Generic[_RefValue]):
2825

2926
def __init__(self, initial_value: _RefValue) -> None:
3027
self.current = initial_value
28+
"""The present value"""
3129

3230
def set_current(self, new: _RefValue) -> _RefValue:
3331
"""Set the current value and return what is now the old value

src/idom/widgets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def World():
190190
Notebook where one might want multiple active views which can all be interacted
191191
with at the same time.
192192
193-
Refer to :func:`idom.server.imperative_server_mount` for a reference usage.
193+
See :func:`idom.server.prefab.multiview_server` for a reference usage.
194194
"""
195195
views: Dict[str, ComponentConstructor] = {}
196196

0 commit comments

Comments
 (0)