Skip to content

Commit 15b1a66

Browse files
authored
Remove Put methods (#241)
1 parent 3da35f0 commit 15b1a66

File tree

7 files changed

+6
-107
lines changed

7 files changed

+6
-107
lines changed

src/fastcs/control_system.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from fastcs.controller import BaseController, Controller
1010
from fastcs.controller_api import ControllerAPI
11-
from fastcs.cs_methods import Command, Put, Scan
11+
from fastcs.cs_methods import Command, Scan
1212
from fastcs.exceptions import FastCSError
1313
from fastcs.logging import logger as _fastcs_logger
1414
from fastcs.tracer import Tracer
@@ -46,7 +46,6 @@ def __init__(
4646
self._loop.run_until_complete(controller.attribute_initialise())
4747
validate_hinted_attributes(controller)
4848
self.controller_api = build_controller_api(controller)
49-
self._link_process_tasks()
5049

5150
self._scan_coros, self._initial_coros = (
5251
self.controller_api.get_scan_and_initial_coros()
@@ -72,10 +71,6 @@ def run(self):
7271
self._loop.add_signal_handler(signal.SIGTERM, serve.cancel)
7372
self._loop.run_until_complete(serve)
7473

75-
def _link_process_tasks(self):
76-
for controller_api in self.controller_api.walk_api():
77-
controller_api.link_put_tasks()
78-
7974
async def _run_initial_coros(self):
8075
for coro in self._initial_coros:
8176
await coro()
@@ -181,13 +176,10 @@ def build_controller_api(controller: Controller) -> ControllerAPI:
181176

182177
def _build_controller_api(controller: BaseController, path: list[str]) -> ControllerAPI:
183178
scan_methods: dict[str, Scan] = {}
184-
put_methods: dict[str, Put] = {}
185179
command_methods: dict[str, Command] = {}
186180
for attr_name in dir(controller):
187181
attr = getattr(controller, attr_name)
188182
match attr:
189-
case Put(enabled=True):
190-
put_methods[attr_name] = attr
191183
case Scan(enabled=True):
192184
scan_methods[attr_name] = attr
193185
case Command(enabled=True):
@@ -199,7 +191,6 @@ def _build_controller_api(controller: BaseController, path: list[str]) -> Contro
199191
path=path,
200192
attributes=controller.attributes,
201193
scan_methods=scan_methods,
202-
put_methods=put_methods,
203194
command_methods=command_methods,
204195
sub_apis={
205196
name: _build_controller_api(sub_controller, path + [name])

src/fastcs/controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class method and a controller instance, so that it can be called from any
100100
101101
"""
102102
# Lazy import to avoid circular references
103-
from fastcs.cs_methods import UnboundCommand, UnboundPut, UnboundScan
103+
from fastcs.cs_methods import UnboundCommand, UnboundScan
104104

105105
# Using a dictionary instead of a set to maintain order.
106106
class_dir = {key: None for key in dir(type(self)) if not key.startswith("_")}
@@ -117,7 +117,7 @@ class method and a controller instance, so that it can be called from any
117117
attr = getattr(self, attr_name, None)
118118
if isinstance(attr, Attribute):
119119
setattr(self, attr_name, deepcopy(attr))
120-
elif isinstance(attr, UnboundPut | UnboundScan | UnboundCommand):
120+
elif isinstance(attr, UnboundScan | UnboundCommand):
121121
setattr(self, attr_name, attr.bind(self))
122122

123123
def _validate_io(self, ios: Sequence[AttributeIO[T, AttributeIORefT]]):

src/fastcs/controller_api.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
from dataclasses import dataclass, field
55

66
from fastcs.attribute_io_ref import AttributeIORef
7-
from fastcs.attributes import ONCE, Attribute, AttrR, AttrW
8-
from fastcs.cs_methods import Command, Put, Scan
9-
from fastcs.exceptions import FastCSError
7+
from fastcs.attributes import ONCE, Attribute, AttrR
8+
from fastcs.cs_methods import Command, Scan
109
from fastcs.logging import logger as _fastcs_logger
1110
from fastcs.tracer import Tracer
1211

@@ -22,7 +21,6 @@ class ControllerAPI:
2221
"""Path within controller tree (empty if this is the root)"""
2322
attributes: dict[str, Attribute] = field(default_factory=dict)
2423
command_methods: dict[str, Command] = field(default_factory=dict)
25-
put_methods: dict[str, Put] = field(default_factory=dict)
2624
scan_methods: dict[str, Scan] = field(default_factory=dict)
2725
sub_apis: dict[str, "ControllerAPI"] = field(default_factory=dict)
2826
"""APIs of the sub controllers of the `Controller` this API was built from"""
@@ -44,20 +42,6 @@ def __repr__(self):
4442
ControllerAPI(path={self.path}, sub_apis=[{", ".join(self.sub_apis.keys())}])\
4543
"""
4644

47-
def link_put_tasks(self) -> None:
48-
for name, method in self.put_methods.items():
49-
name = name.removeprefix("put_")
50-
51-
attribute = self.attributes[name]
52-
match attribute:
53-
case AttrW():
54-
attribute.set_on_put_callback(method.fn)
55-
case _:
56-
raise FastCSError(
57-
f"Attribute type {type(attribute)} does not"
58-
f"support put operations for {name}"
59-
)
60-
6145
def get_scan_and_initial_coros(self) -> tuple[list[Callable], list[Callable]]:
6246
scan_dict: dict[float, list[Callable]] = defaultdict(list)
6347
initial_coros: list[Callable] = []

src/fastcs/cs_methods.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,6 @@ async def __call__(self):
125125
return await self._fn()
126126

127127

128-
class Put(Method[BaseController]):
129-
"""Why don't know what this is for."""
130-
131-
def __init__(self, fn: PutCallback):
132-
super().__init__(fn)
133-
134-
def _validate(self, fn: PutCallback) -> None:
135-
super()._validate(fn)
136-
137-
if not len(self.parameters) == 1:
138-
raise FastCSError("Put method can only take one argument")
139-
140-
async def __call__(self, value: Any):
141-
return await self._fn(value)
142-
143-
144128
class UnboundCommand(Method[Controller_T]):
145129
"""A wrapper of an unbound `Controller` method to be bound into a `Command`.
146130
@@ -201,22 +185,3 @@ def bind(self, controller: Controller_T) -> Scan:
201185

202186
def __call__(self):
203187
raise method_not_bound_error
204-
205-
206-
class UnboundPut(Method[Controller_T]):
207-
"""Unbound version of `Put`."""
208-
209-
def __init__(self, fn: UnboundPutCallback[Controller_T]) -> None:
210-
super().__init__(fn)
211-
212-
def _validate(self, fn: UnboundPutCallback[Controller_T]) -> None:
213-
super()._validate(fn)
214-
215-
if not len(self.parameters) == 2:
216-
raise FastCSError("Put method can only take one argument")
217-
218-
def bind(self, controller: Controller_T) -> Put:
219-
return Put(MethodType(self.fn, controller))
220-
221-
def __call__(self):
222-
raise method_not_bound_error

src/fastcs/wrappers.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Controller_T,
55
UnboundCommand,
66
UnboundCommandCallback,
7-
UnboundPut,
8-
UnboundPutCallback,
97
UnboundScan,
108
UnboundScanCallback,
119
)
@@ -26,11 +24,6 @@ def wrapper(fn: UnboundScanCallback[Controller_T]) -> UnboundScan[Controller_T]:
2624
return wrapper
2725

2826

29-
def put(fn: UnboundPutCallback[Controller_T]) -> UnboundPut[Controller_T]:
30-
"""Sets up a put over the wrapped method."""
31-
return UnboundPut(fn)
32-
33-
3427
def command(
3528
*, group: str | None = None
3629
) -> Callable[[UnboundCommandCallback[Controller_T]], UnboundCommand[Controller_T]]:

tests/assertable_controller.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ def __init__(self, controller: Controller, mocker: MockerFixture) -> None:
8282
# Copy its fields
8383
self.attributes = controller_api.attributes
8484
self.command_methods = controller_api.command_methods
85-
self.put_methods = controller_api.put_methods
8685
self.scan_methods = controller_api.scan_methods
8786
self.sub_apis = controller_api.sub_apis
8887

tests/test_cs_methods.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
import pytest
22

33
from fastcs.controller import Controller
4-
from fastcs.cs_methods import (
5-
Command,
6-
Method,
7-
Put,
8-
Scan,
9-
UnboundCommand,
10-
UnboundPut,
11-
UnboundScan,
12-
)
4+
from fastcs.cs_methods import Command, Method, Scan, UnboundCommand, UnboundScan
135
from fastcs.exceptions import FastCSError
146

157

@@ -90,28 +82,3 @@ async def update_nothing_with_arg(self, arg):
9082
assert scan.period == 1.0
9183

9284
await scan()
93-
94-
95-
@pytest.mark.asyncio
96-
async def test_unbound_put():
97-
class TestController(Controller):
98-
async def put_value(self, value):
99-
pass
100-
101-
async def put_no_value(self):
102-
pass
103-
104-
unbound_put = UnboundPut(TestController.put_value)
105-
106-
with pytest.raises(NotImplementedError):
107-
await unbound_put()
108-
109-
with pytest.raises(FastCSError):
110-
UnboundPut(TestController.put_no_value) # type: ignore
111-
112-
with pytest.raises(FastCSError):
113-
Put(TestController().put_no_value) # type: ignore
114-
115-
put = unbound_put.bind(TestController())
116-
117-
await put(1)

0 commit comments

Comments
 (0)