Skip to content

Commit 1cce8ea

Browse files
authored
fix: Exposed submodules in fastcs.__init__ (#139)
* We can avoid circular imports in typing by importing from the module. * Also added docstrings so api parsing passes
1 parent 5aa7a12 commit 1cce8ea

37 files changed

+169
-21
lines changed

docs/conf.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,27 @@
7171
("py:class", "'object'"),
7272
("py:class", "'id'"),
7373
("py:class", "typing_extensions.Literal"),
74+
# Doesn't work even with asyncio intersphinx mapping
75+
("py:class", "asyncio.events.AbstractEventLoop"),
76+
("py:class", "asyncio.streams.StreamReader"),
77+
("py:class", "asyncio.streams.StreamWriter"),
78+
# Annoying error:
79+
# docstring of collections.abc.Callable:1: WARNING:
80+
# 'any' reference target not found: self [ref.any]
81+
("any", "self"),
82+
# p4p doesn't have intersphinx mapping
83+
("py:class", "p4p.server.StaticProvider"),
84+
("py:class", "p4p.nt.scalar.NTScalar"),
85+
("py:class", "p4p.nt.enum.NTEnum"),
86+
("py:class", "p4p.nt.ndarray.NTNDArray"),
87+
("py:class", "p4p.nt.NTTable"),
88+
# Problems in FastCS itself
89+
("py:class", "fastcs.transport.epics.pva.pvi_tree._PviSignalInfo"),
90+
# TypeVar without docstrings still give warnings
91+
("py:class", "fastcs.datatypes.T_Numerical"),
92+
("py:class", "strawberry.schema.schema.Schema"),
7493
]
75-
nitpick_ignore_regex = [
76-
("py:class", "fastcs.*.T"),
77-
]
94+
nitpick_ignore_regex = [("py:class", "fastcs.*.T")]
7895

7996
# Both the class’ and the __init__ method’s docstring are concatenated and
8097
# inserted into the main body of the autoclass directive
@@ -112,7 +129,9 @@
112129

113130
# This means you can link things like `str` and `asyncio` to the relevant
114131
# docs in the python documentation.
115-
intersphinx_mapping = {"python": ("https://docs.python.org/3/", None)}
132+
intersphinx_mapping = {
133+
"python": ("https://docs.python.org/3/", None),
134+
}
116135

117136
# A dictionary of graphviz graph attributes for inheritance diagrams.
118137
inheritance_graph_attrs = {"rankdir": "TB"}

src/fastcs/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
Version number as calculated by https://github.com/pypa/setuptools_scm
77
"""
88

9-
from ._version import __version__
9+
from . import attributes as attributes
10+
from . import controller as controller
11+
from . import cs_methods as cs_methods
12+
from . import datatypes as datatypes
13+
from . import transport as transport
14+
from ._version import __version__ as __version__
1015
from .launch import FastCS as FastCS
11-
from .launch import launch as launch
12-
13-
__all__ = ["__version__"]

src/fastcs/attributes.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from enum import Enum
66
from typing import Any, Generic, Protocol, runtime_checkable
77

8+
import fastcs
9+
810
from .datatypes import ATTRIBUTE_TYPES, AttrCallback, DataType, T
911

1012

@@ -20,7 +22,9 @@ class AttrMode(Enum):
2022
class Sender(Protocol):
2123
"""Protocol for setting the value of an ``Attribute``."""
2224

23-
async def put(self, controller: Any, attr: AttrW, value: Any) -> None:
25+
async def put(
26+
self, controller: fastcs.controller.BaseController, attr: AttrW, value: Any
27+
) -> None:
2428
pass
2529

2630

@@ -31,7 +35,9 @@ class Updater(Protocol):
3135
# If update period is None then the attribute will not be updated as a task.
3236
update_period: float | None = None
3337

34-
async def update(self, controller: Any, attr: AttrR) -> None:
38+
async def update(
39+
self, controller: fastcs.controller.BaseController, attr: AttrR
40+
) -> None:
3541
pass
3642

3743

@@ -45,7 +51,9 @@ class Handler(Sender, Updater, Protocol):
4551
class SimpleHandler(Handler):
4652
"""Handler for internal parameters"""
4753

48-
async def put(self, controller: Any, attr: AttrW, value: Any):
54+
async def put(
55+
self, controller: fastcs.controller.BaseController, attr: AttrW, value: Any
56+
):
4957
await attr.update_display_without_process(value)
5058

5159
if isinstance(attr, AttrRW):

src/fastcs/backend.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212

1313
class Backend:
14+
"""For keeping track of tasks during FastCS serving."""
15+
1416
def __init__(
1517
self,
1618
controller: Controller,
@@ -163,6 +165,7 @@ async def scan_coro() -> None:
163165

164166

165167
def build_controller_api(controller: Controller) -> ControllerAPI:
168+
"""Build a `ControllerAPI` for a `BaseController` and its sub controllers"""
166169
return _build_controller_api(controller, [])
167170

168171

src/fastcs/connections/ip_connection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44

55
class DisconnectedError(Exception):
6+
"""Raised if the ip connection is disconnected."""
7+
68
pass
79

810

@@ -14,6 +16,8 @@ class IPConnectionSettings:
1416

1517
@dataclass
1618
class StreamConnection:
19+
"""For reading and writing to a stream."""
20+
1721
reader: asyncio.StreamReader
1822
writer: asyncio.StreamWriter
1923

@@ -41,6 +45,8 @@ async def close(self):
4145

4246

4347
class IPConnection:
48+
"""For connecting to an ip using a `StreamConnection`."""
49+
4450
def __init__(self):
4551
self.__connection = None
4652

src/fastcs/connections/serial_connection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66

77
class NotOpenedError(Exception):
8+
"""If the serial stream is not opened."""
9+
810
pass
911

1012

@@ -15,6 +17,8 @@ class SerialConnectionSettings:
1517

1618

1719
class SerialConnection:
20+
"""A serial connection."""
21+
1822
def __init__(self):
1923
self.stream = None
2024
self._lock = asyncio.Lock()

src/fastcs/controller.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88

99
class BaseController:
10+
"""Base class for controller."""
11+
1012
#: Attributes passed from the device at runtime.
1113
attributes: dict[str, Attribute]
1214

@@ -29,7 +31,7 @@ def __init__(
2931

3032
@property
3133
def path(self) -> list[str]:
32-
"""Path prefix of attributes, recursively including parent ``Controller``s."""
34+
"""Path prefix of attributes, recursively including parent Controllers."""
3335
return self._path
3436

3537
def set_path(self, path: list[str]):

src/fastcs/controller_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class ControllerAPI:
2020
description: str | None = None
2121

2222
def walk_api(self) -> Iterator["ControllerAPI"]:
23-
"""Walk through all the nested `ControllerAPIs` of this `ControllerAPI`
23+
"""Walk through all the nested `ControllerAPI` s of this `ControllerAPI`.
2424
25-
yields: `ControllerAPI`s from a depth-first traversal of the tree, including
26-
self.
25+
Yields the `ControllerAPI` s from a depth-first traversal of the tree,
26+
including self.
2727
2828
"""
2929
yield self

src/fastcs/cs_methods.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ async def __call__(self):
123123

124124

125125
class Put(Method[BaseController]):
126+
"""Why don't know what this is for."""
127+
126128
def __init__(self, fn: PutCallback):
127129
super().__init__(fn)
128130

@@ -142,7 +144,7 @@ class UnboundCommand(Method[Controller_T]):
142144
This generic class stores an unbound `Controller` method - effectively a function
143145
that takes an instance of a specific `Controller` type (`Controller_T`). Instances
144146
of this class can be added at `Controller` definition, either manually or with use
145-
of the `@command` wrapper, to register the method to be included in the API of the
147+
of the `command` wrapper, to register the method to be included in the API of the
146148
`Controller`. When the `Controller` is instantiated, these instances will be bound
147149
to the instance, creating a `Command` instance.
148150
"""
@@ -171,7 +173,7 @@ class UnboundScan(Method[Controller_T]):
171173
This generic class stores an unbound `Controller` method - effectively a function
172174
that takes an instance of a specific `Controller` type (`Controller_T`). Instances
173175
of this class can be added at `Controller` definition, either manually or with use
174-
of the `@scan` wrapper, to register the method to be included in the API of the
176+
of the `scan` wrapper, to register the method to be included in the API of the
175177
`Controller`. When the `Controller` is instantiated, these instances will be bound
176178
to the instance, creating a `Scan` instance.
177179
"""
@@ -199,6 +201,8 @@ def __call__(self):
199201

200202

201203
class UnboundPut(Method[Controller_T]):
204+
"""Unbound version of `Put`."""
205+
202206
def __init__(self, fn: UnboundPutCallback[Controller_T]) -> None:
203207
super().__init__(fn)
204208

src/fastcs/exceptions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
class FastCSException(Exception):
2-
pass
2+
"""Base class for general problems in the running of a FastCS transport."""
33

44

55
class LaunchError(FastCSException):
6-
pass
6+
"""For when there is an error in launching FastCS with the given
7+
transports and controller.
8+
"""

0 commit comments

Comments
 (0)