Skip to content

Commit 6b79698

Browse files
author
Joel Collins
committed
Reverted to current_labthing function
1 parent 070bfcd commit 6b79698

File tree

18 files changed

+102
-65
lines changed

18 files changed

+102
-65
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Code formatting ([a86bc21](https://github.com/labthings/python-labthings/commit/a86bc21))
4040
* Code formatting ([9399433](https://github.com/labthings/python-labthings/commit/9399433))
4141
* Code formatting ([cc676b7](https://github.com/labthings/python-labthings/commit/cc676b7))
42-
* Created a current_thing LocalProxy ([2b421b8](https://github.com/labthings/python-labthings/commit/2b421b8))
42+
* Created a current_labthing() LocalProxy ([2b421b8](https://github.com/labthings/python-labthings/commit/2b421b8))
4343
* Deleted test file ([2585abd](https://github.com/labthings/python-labthings/commit/2585abd))
4444
* Fix HTTP method check ([8ae6060](https://github.com/labthings/python-labthings/commit/8ae6060))
4545
* FIx OpenAPI formatting ([c90a646](https://github.com/labthings/python-labthings/commit/c90a646))

docs/api_reference/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ LabThing
55
--------
66

77
.. autoclass:: labthings.LabThing
8+
:members:
9+
10+
Module
11+
------
12+
13+
.. automodule:: labthings
814
:members:

src/labthings/__init__.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
1+
# Main LabThing class
12
from .labthing import LabThing
2-
from .wsgi import Server
3+
4+
# Quick-create app+LabThing function
35
from .quick import create_app
4-
from . import views, sync, fields, schema, semantics
6+
7+
# Suggested WSGI+WebSocket server class
8+
from .wsgi import Server
9+
10+
# Functions to speed up finding global objects
11+
from .find import (
12+
current_labthing,
13+
registered_extensions,
14+
registered_components,
15+
find_extension,
16+
find_component,
17+
)
18+
19+
# Synchronisation classes
20+
from .sync import StrictLock, CompositeLock, ClientEvent
21+
22+
# Task management functions
23+
from .tasks import (
24+
current_task,
25+
current_task_stopped,
26+
update_task_progress,
27+
update_task_data,
28+
TaskKillException,
29+
)
30+
31+
# Submodules
32+
from . import extensions
33+
from . import views
34+
from . import fields
35+
from . import schema
36+
from . import semantics
37+
from . import json
538

639
__all__ = [
7-
"LabThing",
8-
"Server",
9-
"create_app",
10-
"views",
11-
"sync",
12-
"fields",
13-
"schema",
14-
"semantics",
40+
"current_labthing()",
41+
"registered_extensions",
42+
"registered_components",
43+
"find_extension",
44+
"find_component",
1545
]
46+

src/labthings/default_views/actions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ..views.marshalling import marshal_with
55
from ..views.args import use_args
66
from ..schema import ActionSchema
7-
from ..find import current_thing
7+
from ..find import current_labthing
88
from .. import fields
99

1010

@@ -14,7 +14,7 @@ class ActionQueue(View):
1414
"""
1515

1616
def get(self):
17-
return ActionSchema(many=True).dump(current_thing.actions.threads)
17+
return ActionSchema(many=True).dump(current_labthing().actions.threads)
1818

1919

2020
class ActionView(View):
@@ -31,7 +31,7 @@ def get(self, task_id):
3131
3232
Includes progress and intermediate data.
3333
"""
34-
task_dict = current_thing.actions.to_dict()
34+
task_dict = current_labthing().actions.to_dict()
3535

3636
if task_id not in task_dict:
3737
return abort(404) # 404 Not Found
@@ -48,7 +48,7 @@ def delete(self, args, task_id):
4848
If the task is finished, deletes its entry.
4949
"""
5050
timeout = args.get("timeout", 5)
51-
task_dict = current_thing.actions.to_dict()
51+
task_dict = current_labthing().actions.to_dict()
5252

5353
if task_id not in task_dict:
5454
return abort(404) # 404 Not Found

src/labthings/default_views/docs/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from flask import render_template, Blueprint, make_response
22

33
from ...views import View
4-
from ...find import current_thing
4+
from ...find import current_labthing
55

66

77
class APISpecView(View):
88
"""OpenAPI v3 documentation"""
99

1010
def get(self):
1111
"""OpenAPI v3 documentation"""
12-
return current_thing.spec.to_dict()
12+
return current_labthing().spec.to_dict()
1313

1414

1515
class SwaggerUIView(View):

src/labthings/default_views/root.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from ..find import current_thing
1+
from ..find import current_labthing
22
from ..views import View
33

44

55
class RootView(View):
66
"""W3C Thing Description"""
77

88
def get(self):
9-
return current_thing.thing_description.to_dict()
9+
return current_labthing().thing_description.to_dict()

src/labthings/default_views/sockets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ..sockets import SocketSubscriber
2-
from ..find import current_thing
2+
from ..find import current_labthing
33

44
import logging
55

@@ -10,7 +10,7 @@
1010
def socket_handler(ws):
1111
# Create a socket subscriber
1212
wssub = SocketSubscriber(ws)
13-
current_thing.subscribers.add(wssub)
13+
current_labthing().subscribers.add(wssub)
1414
logging.info(f"Added subscriber {wssub}")
1515
# Start the socket connection handler loop
1616
while not ws.closed:
@@ -21,7 +21,7 @@ def socket_handler(ws):
2121
if response:
2222
ws.send(response)
2323
# Remove the subscriber once the loop returns
24-
current_thing.subscribers.remove(wssub)
24+
current_labthing().subscribers.remove(wssub)
2525
logging.info(f"Removed subscriber {wssub}")
2626

2727

src/labthings/default_views/tasks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ..views import View
55
from ..views.marshalling import marshal_with
66
from ..schema import TaskSchema
7-
from ..find import current_thing
7+
from ..find import current_labthing
88

99

1010
class TaskList(View):
@@ -18,7 +18,7 @@ def get(self):
1818
logging.warning(
1919
"TaskList is deprecated and will be removed in a future version. Use the Actions list instead."
2020
)
21-
return TaskSchema(many=True).dump(current_thing.actions.threads)
21+
return TaskSchema(many=True).dump(current_labthing().actions.threads)
2222

2323

2424
class TaskView(View):
@@ -40,7 +40,7 @@ def get(self, task_id):
4040
logging.warning(
4141
"TaskView is deprecated and will be removed in a future version. Use the Action view instead."
4242
)
43-
task_dict = current_thing.actions.to_dict()
43+
task_dict = current_labthing().actions.to_dict()
4444

4545
if task_id not in task_dict:
4646
return abort(404) # 404 Not Found
@@ -58,7 +58,7 @@ def delete(self, task_id):
5858
logging.warning(
5959
"TaskView is deprecated and will be removed in a future version. Use the Action view instead."
6060
)
61-
task_dict = current_thing.actions.to_dict()
61+
task_dict = current_labthing().actions.to_dict()
6262

6363
if task_id not in task_dict:
6464
return abort(404) # 404 Not Found

src/labthings/find.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
from flask import current_app, url_for
33
import weakref
44

5-
from werkzeug.local import LocalProxy
6-
75
from .names import EXTENSION_NAME
86

97
__all__ = [
108
"current_app",
119
"url_for",
1210
"current_labthing",
13-
"current_thing",
11+
"current_labthing()",
1412
"registered_extensions",
1513
"registered_components",
1614
"find_component",
@@ -106,6 +104,3 @@ def find_extension(extension_name, labthing_instance=None):
106104
return labthing_instance.extensions[extension_name]
107105
else:
108106
return None
109-
110-
111-
current_thing = LocalProxy(current_labthing)

src/labthings/json/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .encoder import LabThingsJSONEncoder, encode_json
2+
3+
__all__ = ["LabThingsJSONEncoder", "encode_json"]

0 commit comments

Comments
 (0)