Skip to content

Commit 6c968dc

Browse files
Removing unused settings dict features
1 parent dc169d7 commit 6c968dc

3 files changed

Lines changed: 4 additions & 134 deletions

File tree

src/labthings_fastapi/server/__init__.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
object_reference_to_object,
1414
)
1515
from ..actions import ActionManager
16-
from ..thing_settings import ThingSettings
1716
from ..thing import Thing
1817
from ..thing_description.model import ThingDescription
1918
from ..dependencies.thing_server import _thing_servers
@@ -82,9 +81,6 @@ def add_thing(self, thing: Thing, path: str):
8281
# TODO: check for illegal things in `path` - potential security issue.
8382
settings_folder = os.path.join(self.settings_folder, path.lstrip("/"))
8483
os.makedirs(settings_folder, exist_ok=True)
85-
thing._labthings_thing_settings = ThingSettings(
86-
os.path.join(settings_folder, "settings.json")
87-
)
8884
thing.attach_to_server(self, path, os.path.join(settings_folder, "settings.json"))
8985

9086
@asynccontextmanager
@@ -117,17 +113,6 @@ async def lifespan(self, app: FastAPI):
117113
for name, thing in self.things.items():
118114
# Remove the blocking portal - the event loop is about to stop.
119115
thing._labthings_blocking_portal = None
120-
try:
121-
if thing._labthings_thing_settings:
122-
thing._labthings_thing_settings.write_to_file()
123-
except PermissionError:
124-
logging.warning(
125-
f"Could not write {name} settings to disk: permission error."
126-
)
127-
except FileNotFoundError:
128-
logging.warning(
129-
f"Could not write {name} settings, folder not found"
130-
)
131116

132117
self.blocking_portal = None
133118

src/labthings_fastapi/thing.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .thing_description import validation
2626
from .utilities.introspection import get_summary, get_docstring
2727
from .websockets import websocket_endpoint, WebSocket
28-
from .thing_settings import ThingSettings
28+
2929

3030
if TYPE_CHECKING:
3131
from .server import ThingServer
@@ -130,30 +130,16 @@ def settings(self):
130130
_setting_storage_path: Optional[str] = None
131131

132132
@property
133-
def setting_storage_path(self) -> ThingSettings:
133+
def setting_storage_path(self) -> str:
134134
"""The storage path for settings. This is set at runtime."""
135135
return self._setting_storage_path
136136

137137
def save_settings(self):
138+
"""This is automattically called when a setting is updated with a setter"""
138139
if self.settings is not None:
139-
setting_dict = {name: self.__dict__[name] for name in self.settings}
140+
setting_dict = {name: getattr(self, name) for name in self.settings}
140141
logging.warning(f'This should save {setting_dict} to {self._setting_storage_path}')
141142

142-
_labthings_thing_settings: Optional[ThingSettings] = None
143-
144-
@property
145-
def thing_settings(self) -> ThingSettings:
146-
"""A dictionary that can be used to persist settings between runs"""
147-
if self._labthings_thing_settings is None:
148-
raise RuntimeError(
149-
"Settings may not be accessed before we are attached to the server."
150-
)
151-
return self._labthings_thing_settings
152-
153-
@thing_settings.setter
154-
def thing_settings(self, newsettings: ThingSettings):
155-
self.thing_settings.replace(newsettings)
156-
157143
_labthings_thing_state: Optional[dict] = None
158144

159145
@property

src/labthings_fastapi/thing_settings.py

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)