Commit 36334ed7 authored by jtc42's avatar jtc42
Browse files

Moved to a LabThings dependency for server

parent a1223d8b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ if "%SPHINXBUILD%" == "" (
set SOURCEDIR=source
set BUILDDIR=build

set SPHINXOPTS="-E"

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
+1 −1
Original line number Diff line number Diff line
@@ -3,5 +3,5 @@ Classes and Modules

Extension class
---------------
.. autoclass:: openflexure_microscope.common.flask_labthings.extensions.BaseExtension
.. autoclass:: labthings.server.extensions.BaseExtension
    :members:
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ from openflexure_microscope.plugins import MicroscopePlugin
from openflexure_microscope.api.views import MicroscopeViewPlugin
from openflexure_microscope.api.utilities import JsonResponse

from openflexure_microscope.common.labthings_core.tasks import taskify
from labthings.core.tasks import taskify

import os
import time
+4 −4
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ Tasks are introduced to manage long-running functions in a way that does not blo
the use of tasks, long-running functions would block an HTTP response until the function returns, often 
resulting in a timeout.

To prevent this, any function can be offloaded to a background task. This is done through the :py:meth:`openflexure_microscope.common.tasks.taskify` 
To prevent this, any function can be offloaded to a background task. This is done through the :py:meth:`labthings.tasks.taskify` 
function, by calling ``taskify(<long_running_function>)(*args, **kwargs)``. Internally, the ``tasks`` submodule stores a list
of all requested tasks, which themselves contain a ``state`` dictionary. This dictionary stores the status of the task (if it
is idle, running, error, or success), information about the start and end times, a unique task ID, and the return value of 
@@ -38,7 +38,7 @@ An example of a long running task may look like:
.. code-block:: python

    from openflexure_microscope.plugins import MicroscopeViewPlugin
    from openflexure_microscope.common.tasks import taskify
    from labthings.tasks import taskify

    class MyPlugin(MicroscopeViewPlugin):
        def post(self):
@@ -63,7 +63,7 @@ the microscope hardware. For example, even if the stage is not actively moving (
within a tile scan), another user should not be able to move the microscope, interrupting the task. Thread locks act
to prevent this.

The camera and stage both contain an instance of :py:class:`openflexure_microscope.common.lock.StrictLock`, named ``lock``.
The camera and stage both contain an instance of :py:class:`labthings.lock.StrictLock`, named ``lock``.
Built-in functions such as capture and move will always acquire this lock for the duration of the function. This ensures
that, for example, simultaneous attemps to move do not occur.

@@ -77,7 +77,7 @@ For example, a timelapse plugin may look like:
    from openflexure_microscope.api.v1.views import MicroscopeViewPlugin
    from openflexure_microscope.api.utilities import JsonResponse

    from openflexure_microscope.common.tasks import taskify
    from labthings.tasks import taskify


    ### MICROSCOPE PLUGIN ###
+5 −5
Original line number Diff line number Diff line
Basic extension structure
=========================

An extension starts as a simple instance of :py:class:`openflexure_microscope.common.flask_labthings.extensions.BaseExtension`. 
An extension starts as a simple instance of :py:class:`labthings.server.extensions.BaseExtension`. 
Each extension is described by a single ``BaseExtension`` instance, containing any number of methods, API views, and additional hardware components. 

In order to access the currently running microscope object, use the :py:func:`openflexure_microscope.common.flask_labthings.find` function, with the argument ``"org.openflexure.microscope"``. Likewise, any new components attached by other extensions can be found using their full name, as above.
In order to access the currently running microscope object, use the :py:func:`labthings.server.find` function, with the argument ``"org.openflexure.microscope"``. Likewise, any new components attached by other extensions can be found using their full name, as above.

A simple extension file, with no API views but application-available methods may look like:

.. code-block:: python

    from openflexure_microscope.common.flask_labthings.extensions import BaseExtension
    from openflexure_microscope.common.flask_labthings.find import find_component
    from labthings.server.extensions import BaseExtension
    from labthings.server.find import find_component


    def identify():
@@ -50,7 +50,7 @@ Once this extension is loaded, any other extensions will have access to your met

.. code-block:: python

    from openflexure_microscope.common.flask_labthings.find import find_extension
    from labthings.server.find import find_extension

    def test_extension_method():
        # Find your extension. Returns None if it hasn't been found.
Loading