diff --git a/openflexure_microscope/api/app.py b/openflexure_microscope/api/app.py index 461f3a71..937c610e 100644 --- a/openflexure_microscope/api/app.py +++ b/openflexure_microscope/api/app.py @@ -82,17 +82,10 @@ for plugin in find_plugins(USER_PLUGINS_PATH): # Attach captures resources labthing.add_resource(views.CaptureList, f"/captures") labthing.register_property(views.CaptureList) -labthing.add_resource( - views.CaptureResource, f"/captures/" -) -labthing.add_resource( - views.CaptureDownload, - f"/captures//download/", -) +labthing.add_resource(views.CaptureResource, f"/captures/") +labthing.add_resource(views.CaptureDownload, f"/captures//download/") labthing.add_resource(views.CaptureTags, f"/captures//tags") -labthing.add_resource( - views.CaptureMetadata, f"/captures//metadata" -) +labthing.add_resource(views.CaptureMetadata, f"/captures//metadata") # Attach settings and status resources labthing.add_resource(views.SettingsProperty, f"/settings") diff --git a/openflexure_microscope/api/utilities.py b/openflexure_microscope/api/utilities.py index 98232ecb..2045ba0f 100644 --- a/openflexure_microscope/api/utilities.py +++ b/openflexure_microscope/api/utilities.py @@ -124,4 +124,4 @@ def init_default_plugins(plugin_path): _DEFAULT_PLUGIN_INIT = """from openflexure_microscope.plugins.v2.autofocus import autofocus_plugin_v2 from openflexure_microscope.plugins.v2.scan import scan_plugin_v2 -__plugins__ = [autofocus_plugin_v2, scan_plugin_v2]""" \ No newline at end of file +__plugins__ = [autofocus_plugin_v2, scan_plugin_v2]""" diff --git a/openflexure_microscope/api/v2/views/actions/camera.py b/openflexure_microscope/api/v2/views/actions/camera.py index ab0b95e5..fe2a707d 100644 --- a/openflexure_microscope/api/v2/views/actions/camera.py +++ b/openflexure_microscope/api/v2/views/actions/camera.py @@ -61,6 +61,7 @@ class GPUPreviewStartAPI(Resource): Optional "window" parameter can be passed to control the position and size of the preview window, in the format ``[x, y, width, height]``. """ + def post(self): microscope = find_device("openflexure_microscope") payload = JsonResponse(request) @@ -84,6 +85,7 @@ class GPUPreviewStopAPI(Resource): """ Start the onboard GPU preview. """ + def post(self): microscope = find_device("openflexure_microscope") microscope.camera.stop_preview() diff --git a/openflexure_microscope/api/v2/views/captures.py b/openflexure_microscope/api/v2/views/captures.py index 3cc5fb85..80afdc24 100644 --- a/openflexure_microscope/api/v2/views/captures.py +++ b/openflexure_microscope/api/v2/views/captures.py @@ -6,7 +6,9 @@ from openflexure_microscope.api.utilities import get_bool, JsonResponse from openflexure_microscope.common.flask_labthings.schema import Schema from openflexure_microscope.common.flask_labthings import fields from openflexure_microscope.common.flask_labthings.resource import Resource -from openflexure_microscope.common.flask_labthings.utilities import description_from_view +from openflexure_microscope.common.flask_labthings.utilities import ( + description_from_view, +) from openflexure_microscope.common.flask_labthings.decorators import marshal_with from openflexure_microscope.common.flask_labthings.find import find_device @@ -30,24 +32,27 @@ class CaptureSchema(Schema): "self": { "href": url_for(CaptureResource.endpoint, id=data.id, _external=True), "mimetype": "application/json", - **description_from_view(CaptureResource) + **description_from_view(CaptureResource), }, "tags": { "href": url_for(CaptureTags.endpoint, id=data.id, _external=True), "mimetype": "application/json", - **description_from_view(CaptureTags) + **description_from_view(CaptureTags), }, "metadata": { "href": url_for(CaptureMetadata.endpoint, id=data.id, _external=True), "mimetype": "application/json", - **description_from_view(CaptureMetadata) + **description_from_view(CaptureMetadata), }, "download": { "href": url_for( - CaptureDownload.endpoint, id=data.id, filename=data.filename, _external=True + CaptureDownload.endpoint, + id=data.id, + filename=data.filename, + _external=True, ), "mimetype": "image/jpeg", - **description_from_view(CaptureDownload) + **description_from_view(CaptureDownload), }, } return data @@ -61,6 +66,7 @@ class CaptureList(Resource): """ List all image captures """ + @marshal_with(CaptureSchema(many=True)) def get(self): microscope = find_device("openflexure_microscope") @@ -99,6 +105,7 @@ class CaptureDownload(Resource): """ Image data for a single image capture """ + def get(self, id, filename): microscope = find_device("openflexure_microscope") @@ -134,6 +141,7 @@ class CaptureTags(Resource): """ Tags associated with a single image capture """ + def get(self, id): microscope = find_device("openflexure_microscope") @@ -184,6 +192,7 @@ class CaptureMetadata(Resource): """ All metadata associated with a single image capture """ + def get(self, id): microscope = find_device("openflexure_microscope") capture_obj = microscope.camera.image_from_id(id) diff --git a/openflexure_microscope/common/flask_labthings/decorators.py b/openflexure_microscope/common/flask_labthings/decorators.py index e911f887..1ffeebed 100644 --- a/openflexure_microscope/common/flask_labthings/decorators.py +++ b/openflexure_microscope/common/flask_labthings/decorators.py @@ -41,4 +41,5 @@ class marshal_with(object): return make_response(self.schema.jsonify(data), code, headers) else: return make_response(self.schema.jsonify(resp)) + return wrapper diff --git a/openflexure_microscope/common/flask_labthings/fields.py b/openflexure_microscope/common/flask_labthings/fields.py index 13ea7da9..32dbfb18 100644 --- a/openflexure_microscope/common/flask_labthings/fields.py +++ b/openflexure_microscope/common/flask_labthings/fields.py @@ -72,7 +72,9 @@ class URLFor(Field): self.view_class = None self.endpoint = endpoint else: - raise RuntimeError(f"Endpoint {endpoint} is not a valid Flask view or endpoint string.") + raise RuntimeError( + f"Endpoint {endpoint} is not a valid Flask view or endpoint string." + ) self.params = kwargs Field.__init__(self, **kwargs) @@ -85,7 +87,9 @@ class URLFor(Field): if hasattr(self.view_class, "endpoint"): self.endpoint = self.view_class.endpoint else: - raise RuntimeError(f"Resource {self.endpoint} has not been added to a LabThing application. Unable to generate URL.") + raise RuntimeError( + f"Resource {self.endpoint} has not been added to a LabThing application. Unable to generate URL." + ) # Generate URL for param_values = {} diff --git a/openflexure_microscope/common/flask_labthings/labthing.py b/openflexure_microscope/common/flask_labthings/labthing.py index c5f4da30..c3662192 100644 --- a/openflexure_microscope/common/flask_labthings/labthing.py +++ b/openflexure_microscope/common/flask_labthings/labthing.py @@ -11,7 +11,14 @@ from . import EXTENSION_NAME class LabThing(object): - def __init__(self, app=None, prefix: str = "", title: str = "", description: str = "", handle_errors: bool = True): + def __init__( + self, + app=None, + prefix: str = "", + title: str = "", + description: str = "", + handle_errors: bool = True, + ): self.app = app self.devices = {} @@ -219,7 +226,7 @@ class LabThing(object): if self.blueprint: if endpoint.startswith(self.blueprint.name): - endpoint = endpoint.split(self.blueprint.name + '.', 1)[-1] + endpoint = endpoint.split(self.blueprint.name + ".", 1)[-1] else: return False return endpoint in self.endpoints @@ -254,4 +261,4 @@ class LabThing(object): return jsonify(td) - # TODO: Add a nicer root resource like the old self-documenting system \ No newline at end of file + # TODO: Add a nicer root resource like the old self-documenting system diff --git a/openflexure_microscope/common/flask_labthings/plugins.py b/openflexure_microscope/common/flask_labthings/plugins.py index 05a431a1..b39ee9b7 100644 --- a/openflexure_microscope/common/flask_labthings/plugins.py +++ b/openflexure_microscope/common/flask_labthings/plugins.py @@ -5,10 +5,7 @@ import copy from importlib import util import sys -from openflexure_microscope.utilities import ( - camel_to_snake, - snake_to_spine, -) +from openflexure_microscope.utilities import camel_to_snake, snake_to_spine class BasePlugin: diff --git a/openflexure_microscope/common/flask_labthings/views/plugins.py b/openflexure_microscope/common/flask_labthings/views/plugins.py index eb6b27b0..35d01b50 100644 --- a/openflexure_microscope/common/flask_labthings/views/plugins.py +++ b/openflexure_microscope/common/flask_labthings/views/plugins.py @@ -36,7 +36,11 @@ def plugins_representation(plugin_dict): } for view_id, view_data in plugin.views.items(): - uri = url_for(f"PluginListResource", _external=True) + "/" + view_data["rule"][1:] + uri = ( + url_for(f"PluginListResource", _external=True) + + "/" + + view_data["rule"][1:] + ) # Make links dictionary if it doesn't yet exist view_d = {"href": uri, **description_from_view(view_data["view"])} diff --git a/openflexure_microscope/common/flask_labthings/views/tasks.py b/openflexure_microscope/common/flask_labthings/views/tasks.py index 8669559f..89fdfe1f 100644 --- a/openflexure_microscope/common/flask_labthings/views/tasks.py +++ b/openflexure_microscope/common/flask_labthings/views/tasks.py @@ -4,7 +4,9 @@ from openflexure_microscope.common.flask_labthings.schema import Schema from openflexure_microscope.common.flask_labthings import fields from openflexure_microscope.common.labthings_core import tasks from openflexure_microscope.common.flask_labthings.resource import Resource -from openflexure_microscope.common.flask_labthings.utilities import description_from_view +from openflexure_microscope.common.flask_labthings.utilities import ( + description_from_view, +) from marshmallow import pre_dump @@ -52,8 +54,8 @@ class TaskSchema(Schema): "self": { "href": url_for(TaskResource.endpoint, id=data.id, _external=True), "mimetype": "application/json", - **description_from_view(TaskResource) - }, + **description_from_view(TaskResource), + } } return data