labthings-fastapi 0.2.0rc1__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/PKG-INFO +1 -1
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/pyproject.toml +1 -1
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/server/__init__.py +7 -10
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/server/fallback.py +21 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/testing.py +35 -1
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/thing_class_settings.py +8 -6
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/.gitignore +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/LICENSE +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/README.md +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/__init__.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/actions.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/base_descriptor.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/client/__init__.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/endpoints.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/example_things/__init__.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/exceptions.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/global_lock.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/invocation_contexts.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/invocations.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/logs.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/middleware/__init__.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/middleware/url_for.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/notifications.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/outputs/__init__.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/outputs/blob.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/outputs/mjpeg_stream.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/properties.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/py.typed +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/server/cli.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/server/config_model.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/server/fallback.html.jinja +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/thing.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/thing_description/__init__.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/thing_description/_model.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/thing_description/td-json-schema-validation.json +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/thing_description/validation.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/thing_server_interface.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/thing_slots.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/types/__init__.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/types/numpy.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/utilities/__init__.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/utilities/introspection.py +0 -0
- {labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/websockets.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: labthings-fastapi
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: An implementation of LabThings using FastAPI
|
|
5
5
|
Project-URL: Homepage, https://github.com/labthings/labthings-fastapi
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/labthings/labthings-fastapi/issues
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/server/__init__.py
RENAMED
|
@@ -146,9 +146,9 @@ class ThingServer:
|
|
|
146
146
|
self._set_url_for_middleware()
|
|
147
147
|
self._add_exception_handlers()
|
|
148
148
|
self.action_manager = ActionManager()
|
|
149
|
-
self.app.include_router(self.action_manager.router(), prefix=self.
|
|
150
|
-
self.app.include_router(blob.router, prefix=self.
|
|
151
|
-
self.app.include_router(self._things_view_router(), prefix=self.
|
|
149
|
+
self.app.include_router(self.action_manager.router(), prefix=self.api_prefix)
|
|
150
|
+
self.app.include_router(blob.router, prefix=self.api_prefix)
|
|
151
|
+
self.app.include_router(self._things_view_router(), prefix=self.api_prefix)
|
|
152
152
|
self.blocking_portal: Optional[BlockingPortal] = None
|
|
153
153
|
self.startup_status: dict[str, str | dict] = {"things": {}}
|
|
154
154
|
global _thing_servers # noqa: F824
|
|
@@ -270,10 +270,7 @@ class ThingServer:
|
|
|
270
270
|
|
|
271
271
|
@property
|
|
272
272
|
def things(self) -> Mapping[str, Thing]:
|
|
273
|
-
"""
|
|
274
|
-
|
|
275
|
-
:return: a dictionary mapping thing paths to `~lt.Thing` instances.
|
|
276
|
-
"""
|
|
273
|
+
"""A read-only mapping of names to `~lt.Thing` instances."""
|
|
277
274
|
return MappingProxyType(self._things)
|
|
278
275
|
|
|
279
276
|
@property
|
|
@@ -286,7 +283,7 @@ class ThingServer:
|
|
|
286
283
|
return self._config.application_config
|
|
287
284
|
|
|
288
285
|
@property
|
|
289
|
-
def
|
|
286
|
+
def api_prefix(self) -> str:
|
|
290
287
|
r"""A string that prefixes all URLs in the application.
|
|
291
288
|
|
|
292
289
|
This will either be empty, or start with a slash and not
|
|
@@ -337,7 +334,7 @@ class ThingServer:
|
|
|
337
334
|
"""
|
|
338
335
|
if name not in self._things:
|
|
339
336
|
raise KeyError(f"No thing named {name} has been added to this server.")
|
|
340
|
-
return f"{self.
|
|
337
|
+
return f"{self.api_prefix}/{name}/"
|
|
341
338
|
|
|
342
339
|
def _create_things(self) -> Mapping[str, Thing]:
|
|
343
340
|
r"""Create the Things, add them to the server, and connect them up if needed.
|
|
@@ -475,7 +472,7 @@ class ThingServer:
|
|
|
475
472
|
"""
|
|
476
473
|
return {
|
|
477
474
|
name: thing.thing_description(
|
|
478
|
-
path=f"{self.
|
|
475
|
+
path=f"{self.api_prefix}/{name}/", base=str(request.base_url)
|
|
479
476
|
)
|
|
480
477
|
for name, thing in thing_server.things.items()
|
|
481
478
|
}
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/server/fallback.py
RENAMED
|
@@ -16,6 +16,7 @@ from traceback import format_exception
|
|
|
16
16
|
from typing import Any, TYPE_CHECKING
|
|
17
17
|
|
|
18
18
|
from fastapi import FastAPI
|
|
19
|
+
from fastapi.middleware.cors import CORSMiddleware
|
|
19
20
|
from fastapi.responses import HTMLResponse
|
|
20
21
|
from jinja2 import Environment, BaseLoader, select_autoescape
|
|
21
22
|
from starlette.responses import RedirectResponse
|
|
@@ -149,6 +150,15 @@ class FallbackApp(FastAPI):
|
|
|
149
150
|
|
|
150
151
|
app = FallbackApp()
|
|
151
152
|
|
|
153
|
+
# Add middleware so contacting the the fallback server doesn't throw CORS errors.
|
|
154
|
+
app.add_middleware(
|
|
155
|
+
CORSMiddleware,
|
|
156
|
+
allow_origins=["*"],
|
|
157
|
+
allow_credentials=True,
|
|
158
|
+
allow_methods=["*"],
|
|
159
|
+
allow_headers=["*"],
|
|
160
|
+
)
|
|
161
|
+
|
|
152
162
|
|
|
153
163
|
@app.get("/")
|
|
154
164
|
async def root() -> HTMLResponse:
|
|
@@ -159,6 +169,17 @@ async def root() -> HTMLResponse:
|
|
|
159
169
|
return app.fallback_page()
|
|
160
170
|
|
|
161
171
|
|
|
172
|
+
@app.get("/labthings_fallback")
|
|
173
|
+
async def fallback_route() -> bool:
|
|
174
|
+
"""Return True, this is a LabThings Fallback Server.
|
|
175
|
+
|
|
176
|
+
Use this to check over the API if this is a LabThings Fallback Server.
|
|
177
|
+
|
|
178
|
+
:return: returns True. This is a LabThings Fallback Server.
|
|
179
|
+
"""
|
|
180
|
+
return True
|
|
181
|
+
|
|
182
|
+
|
|
162
183
|
def _format_error_and_traceback(context: FallbackContext) -> tuple[str, str]:
|
|
163
184
|
"""Format the error and traceback.
|
|
164
185
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Test harnesses to help with writitng tests for things.."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
-
from collections.abc import Iterator
|
|
4
|
+
from collections.abc import Iterator, Sequence
|
|
5
5
|
from concurrent.futures import Future
|
|
6
6
|
from contextlib import contextmanager
|
|
7
7
|
from typing import (
|
|
@@ -270,3 +270,37 @@ def use_dummy_url_for() -> Iterator[None]:
|
|
|
270
270
|
"""Use the dummy URL for function in the context variable."""
|
|
271
271
|
with set_url_for_context(dummy_url_for):
|
|
272
272
|
yield
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def manually_connect_thing_slot(
|
|
276
|
+
host: Thing,
|
|
277
|
+
slot_name: str,
|
|
278
|
+
target: Thing | Sequence[Thing],
|
|
279
|
+
) -> None:
|
|
280
|
+
"""Manually connect a thing_slot.
|
|
281
|
+
|
|
282
|
+
This will accept either a single `Thing` instance or a sequence
|
|
283
|
+
of `Thing` instances. If `Mock` instances are used, note that they
|
|
284
|
+
must pass an `isinstance` test, so should use the ``spec`` argument
|
|
285
|
+
to specify the correct class for the `~lt.thing_slot` being mocked.
|
|
286
|
+
Mock instances must also provide a unique ``name`` attribute.
|
|
287
|
+
|
|
288
|
+
:param host: the `~lt.Thing` on which the slot is defined.
|
|
289
|
+
:param slot_name: the name of the `~lt.thing_slot`.
|
|
290
|
+
:param target: the `~lt.Thing` or sequence of Things it should be connected to.
|
|
291
|
+
If a sequence of multiple Thing are passed, their names are used to create a
|
|
292
|
+
mapping.
|
|
293
|
+
:raises KeyError: if multiple targets are specified, but they do not
|
|
294
|
+
have unique names.
|
|
295
|
+
"""
|
|
296
|
+
if not isinstance(target, Sequence):
|
|
297
|
+
names: str | Sequence[str] = target.name
|
|
298
|
+
things = {target.name: target}
|
|
299
|
+
else:
|
|
300
|
+
names = [t.name for t in target]
|
|
301
|
+
if len(set(names)) != len(names):
|
|
302
|
+
msg = f"Thing slot targets {names} are not uniquely named."
|
|
303
|
+
raise KeyError(msg)
|
|
304
|
+
things = {t.name: t for t in target}
|
|
305
|
+
slot = getattr(host.__class__, slot_name)
|
|
306
|
+
slot.connect(host, target=names, things=things)
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/thing_class_settings.py
RENAMED
|
@@ -89,17 +89,19 @@ def get_validate_properties_on_set(cls: "type[Thing]") -> bool:
|
|
|
89
89
|
:return: whether validation should be performed.
|
|
90
90
|
"""
|
|
91
91
|
settings = get_class_settings(cls)
|
|
92
|
-
|
|
92
|
+
value = settings.get(
|
|
93
|
+
"validate_properties_on_set",
|
|
94
|
+
False,
|
|
95
|
+
)
|
|
96
|
+
if not value:
|
|
93
97
|
warnings.warn(
|
|
94
98
|
DefaultWillChangeWarning(
|
|
95
99
|
"`get_validate_properties_on_set` will become `True` by default "
|
|
96
|
-
"in the future
|
|
100
|
+
"in the future, and may become the only option. "
|
|
101
|
+
"Set this property to `True` in "
|
|
97
102
|
f"`{cls.__module__}.{cls.__name__}._class_settings` "
|
|
98
103
|
"to eliminate this warning."
|
|
99
104
|
),
|
|
100
105
|
stacklevel=3,
|
|
101
106
|
)
|
|
102
|
-
return
|
|
103
|
-
"validate_properties_on_set",
|
|
104
|
-
False,
|
|
105
|
-
)
|
|
107
|
+
return value
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/base_descriptor.py
RENAMED
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/client/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/invocation_contexts.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/middleware/__init__.py
RENAMED
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/middleware/url_for.py
RENAMED
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/notifications.py
RENAMED
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/outputs/__init__.py
RENAMED
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/outputs/blob.py
RENAMED
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/outputs/mjpeg_stream.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/server/config_model.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/types/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{labthings_fastapi-0.2.0rc1 → labthings_fastapi-0.2.1}/src/labthings_fastapi/utilities/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|