Skip to content

Commit c1b8e2c

Browse files
committed
Fix links and RST formatting
There was a bad indent in the properties module level docstring, and a few imports that confused Sphinx when making cross-references. I've moved an exception and tweaked the way Thing._thing_server_interface is declared to improve the docs: this should not change any code.
1 parent d25f618 commit c1b8e2c

File tree

6 files changed

+36
-29
lines changed

6 files changed

+36
-29
lines changed

src/labthings_fastapi/actions/__init__.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,22 @@
3535
from ..exceptions import (
3636
InvocationCancelledError,
3737
InvocationError,
38+
NoBlobManagerError,
3839
)
3940
from ..outputs.blob import BlobIOContextDep, blobdata_to_url_ctx
40-
from ..invocation_contexts import (
41-
CancelEvent,
42-
get_cancel_event,
43-
set_invocation_id,
44-
)
41+
from .. import invocation_contexts
4542

4643
if TYPE_CHECKING:
4744
# We only need these imports for type hints, so this avoids circular imports.
4845
from ..descriptors import ActionDescriptor
4946
from ..thing import Thing
5047

51-
ACTION_INVOCATIONS_PATH = "/action_invocations"
52-
"""The API route used to list `.Invocation` objects."""
5348

49+
__all__ = ["ACTION_INVOCATIONS_PATH", "Invocation", "ActionManager"]
5450

55-
class NoBlobManagerError(RuntimeError):
56-
"""Raised if an API route accesses Invocation outputs without a BlobIOContextDep.
5751

58-
Any access to an invocation output must have BlobIOContextDep as a dependency, as
59-
the output may be a blob, and the blob needs this context to resolve its URL.
60-
"""
52+
ACTION_INVOCATIONS_PATH = "/action_invocations"
53+
"""The API route used to list `.Invocation` objects."""
6154

6255

6356
class Invocation(Thread):
@@ -197,9 +190,9 @@ def thing(self) -> Thing:
197190
return thing
198191

199192
@property
200-
def cancel_hook(self) -> CancelEvent:
193+
def cancel_hook(self) -> invocation_contexts.CancelEvent:
201194
"""The cancel event associated with this Invocation."""
202-
return get_cancel_event(self.id)
195+
return invocation_contexts.get_cancel_event(self.id)
203196

204197
def cancel(self) -> None:
205198
"""Cancel the task by requesting the code to stop.
@@ -278,7 +271,7 @@ def run(self) -> None:
278271
logger = self.thing.logger
279272
# The line below saves records matching our ID to ``self._log``
280273
add_thing_log_destination(self.id, self._log)
281-
with set_invocation_id(self.id):
274+
with invocation_contexts.set_invocation_id(self.id):
282275
try:
283276
action.emit_changed_event(self.thing, self._status.value)
284277

src/labthings_fastapi/decorators/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
----------
2626
2727
As with Actions, Properties can be declared by decorating either a function, or
28-
an attribute, with :deco:`.thing_property`. You can use the decorator either on
28+
an attribute, with :deco:`.property`. You can use the decorator either on
2929
a function (in which case that
30-
function acts as the "getter" just like with Python's :deco`property` decorator).
30+
function acts as the "getter" just like with Python's :deco:`property` decorator).
3131
3232
Events
3333
------

src/labthings_fastapi/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,11 @@ class LogConfigurationError(RuntimeError):
137137
certain handlers and filters to be set up. This exception is raised if they
138138
cannot be added, or if they are not present when they are needed.
139139
"""
140+
141+
142+
class NoBlobManagerError(RuntimeError):
143+
"""Raised if an API route accesses Invocation outputs without a BlobIOContextDep.
144+
145+
Any access to an invocation output must have BlobIOContextDep as a dependency, as
146+
the output may be a blob, and the blob needs this context to resolve its URL.
147+
"""

src/labthings_fastapi/properties.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
import labthings_fastapi as lt
1313
14+
1415
class Counter(lt.Thing):
1516
"A counter that knows what's remaining."
1617
@@ -29,19 +30,19 @@ def remaining(self) -> int:
2930
def remaining(self, value: int) -> None:
3031
self.target = self.count + value
3132
32-
The first two properties are simple variables: they may be read and assigned
33-
to, and will behave just like a regular variable. Their syntax is similar to
34-
`dataclasses` or `pydantic` in that `.property` is used as a "field specifier"
35-
to set options like the default value, and the type annotation is on the
36-
class attribute. Documentation is in strings immediately following the
37-
properties, which is understood by most automatic documentation tools.
33+
The first two properties are simple variables: they may be read and assigned
34+
to, and will behave just like a regular variable. Their syntax is similar to
35+
`dataclasses` or `pydantic` in that `.property` is used as a "field specifier"
36+
to set options like the default value, and the type annotation is on the
37+
class attribute. Documentation is in strings immediately following the
38+
properties, which is understood by most automatic documentation tools.
3839
39-
``remaining`` is defined using a "getter" function, meaning this code will
40-
be run each time ``counter.remaining`` is accessed. Its type will be the
41-
return type of the function, and its docstring will come from the function
42-
too. Setters with only a getter are read-only.
40+
``remaining`` is defined using a "getter" function, meaning this code will
41+
be run each time ``counter.remaining`` is accessed. Its type will be the
42+
return type of the function, and its docstring will come from the function
43+
too. Setters with only a getter are read-only.
4344
44-
Adding a "setter" to properties is optional, and makes them read-write.
45+
Adding a "setter" to properties is optional, and makes them read-write.
4546
"""
4647

4748
from __future__ import annotations
@@ -217,7 +218,7 @@ def property(
217218
218219
This function may be used to define :ref:`wot_properties` in
219220
two ways, as either a decorator or a field specifier. See the
220-
examples in the :mod:`.thing_property` documentation.
221+
examples in the :mod:`.property` documentation.
221222
222223
Properties should always have a type annotation. This type annotation
223224
will be used in automatic documentation and also to serialise the value

src/labthings_fastapi/server/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
# `_thing_servers` is used as a global from `ThingServer.__init__`
3737
from ..outputs.blob import BlobDataManager
3838

39+
__all__ = ["ThingServer"]
40+
3941

4042
ThingSubclass = TypeVar("ThingSubclass", bound=Thing)
4143

src/labthings_fastapi/thing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class Thing:
7979
title: str
8080
"""A human-readable description of the Thing"""
8181

82+
_thing_server_interface: ThingServerInterface
83+
"""Provide access to features of the server that this `.Thing` is attached to."""
84+
8285
def __init__(self, thing_server_interface: ThingServerInterface) -> None:
8386
"""Initialise a Thing.
8487

0 commit comments

Comments
 (0)