Commit 70149e97 authored by jtc42's avatar jtc42
Browse files

Cleaned code structure

parent 79abc3fe
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ from openflexure_microscope.common.flask_labthings.decorators import (
    doc,
    doc_response,
)

from openflexure_microscope.common.flask_labthings import fields
from openflexure_microscope.utilities import filter_dict

+6 −1
Original line number Diff line number Diff line
from openflexure_microscope.api.utilities import JsonResponse
from openflexure_microscope.utilities import get_by_path, set_by_path, create_from_path

from openflexure_microscope.common.labthings_core.utilities import (
    get_by_path,
    set_by_path,
    create_from_path,
)

from openflexure_microscope.common.flask_labthings.find import find_device
from openflexure_microscope.common.flask_labthings.resource import Resource
+6 −1
Original line number Diff line number Diff line
from openflexure_microscope.api.utilities import gen, JsonResponse
from openflexure_microscope.utilities import get_by_path, set_by_path, create_from_path

from openflexure_microscope.common.labthings_core.utilities import (
    get_by_path,
    set_by_path,
    create_from_path,
)

from openflexure_microscope.common.flask_labthings.find import find_device
from openflexure_microscope.common.flask_labthings.resource import Resource
+4 −26
Original line number Diff line number Diff line
@@ -2,8 +2,10 @@ from webargs import flaskparser
from functools import wraps, update_wrapper
from flask import make_response

from .utilities import rupdate
from .spec import update_spec
from openflexure_microscope.common.labthings_core.utilities import rupdate
from openflexure_microscope.common.labthings_core.spec import update_spec

from openflexure_microscope.common.labthings_core.decorators import doc, doc_response


def unpack(value):
@@ -74,27 +76,3 @@ class use_kwargs(use_args):
        """
        kwargs["as_kwargs"] = True
        use_args.__init__(self, schema, **kwargs)


class doc(object):
    def __init__(self, **kwargs):
        self.kwargs = kwargs

    def __call__(self, f):
        # Pass params to call function attribute for external access
        update_spec(f, self.kwargs)
        return f


class doc_response(object):
    def __init__(self, code, description, **kwargs):
        self.code = code
        self.description = description
        self.kwargs = kwargs

    def __call__(self, f):
        # Pass params to call function attribute for external access
        f.__apispec__ = f.__dict__.get("__apispec__", {})
        d = {"responses": {self.code: {"description": self.description, **self.kwargs}}}
        rupdate(f.__apispec__, d)
        return f
+10 −4
Original line number Diff line number Diff line
@@ -7,8 +7,14 @@ import sys
import os
import glob

from openflexure_microscope.common.labthings_core.utilities import get_docstring
from openflexure_microscope.utilities import camel_to_snake, snake_to_spine
from openflexure_microscope.common.labthings_core.utilities import (
    get_docstring,
    camel_to_snake,
    snake_to_spine,
)


# TODO: Move into core?


class BaseExtension:
@@ -134,7 +140,7 @@ def find_instances_in_module(module, class_to_find):
    return objs


def find_extensions_in_file(extension_path, module_name="extensions"):
def find_extensions_in_file(extension_path: str, module_name="extensions"):
    logging.debug(f"Loading extensions from {extension_path}")

    spec = util.spec_from_file_location(module_name, extension_path)
@@ -149,7 +155,7 @@ def find_extensions_in_file(extension_path, module_name="extensions"):
        return find_instances_in_module(mod, BaseExtension)


def find_extensions(extension_dir, module_name="extensions"):
def find_extensions(extension_dir: str, module_name="extensions"):
    logging.debug(f"Loading extensions from {extension_dir}")

    extensions = []
Loading