Skip to content

Commit 5cc4efe

Browse files
committed
Refactor workspace backend handling: remove XML-RPC support, streamline Web API integration
- Removed the StandaloneBackend and LiveBackend classes from workspace.py, consolidating backend functionality. - Updated Workspace class to detect backend mode based on WebApiBackend and StandaloneBackend. - Refactored tests to align with new backend structure, ensuring compatibility with Web API. - Simplified test cases by removing dependencies on XML-RPC and legacy code. - Updated pyproject.toml to remove XML-RPC dependencies.
1 parent 5a440fe commit 5cc4efe

File tree

16 files changed

+1099
-871
lines changed

16 files changed

+1099
-871
lines changed

.vscode/tasks.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@
6767
"type": "shell",
6868
"command": "${command:python.interpreterPath}",
6969
"args": [
70+
"scripts/run_with_env.py",
71+
"${command:python.interpreterPath}",
7072
"-m",
7173
"pytest",
72-
"--live",
73-
"--start-datalab",
74+
// "--start-datalab",
7475
"datalab_kernel/tests/",
75-
"-v",
7676
"--ff"
7777
],
7878
"options": {

Untitled.ipynb

Lines changed: 129 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,10 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 2,
5+
"execution_count": 4,
66
"id": "ac5cee0c-62e1-4b17-890e-9aa443e6503a",
77
"metadata": {},
8-
"outputs": [
9-
{
10-
"ename": "KeyError",
11-
"evalue": "\"Object 'i001' not found. Available objects: [(empty)]\"",
12-
"output_type": "error",
13-
"traceback": [
14-
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
15-
"\u001b[31mKeyError\u001b[39m Traceback (most recent call last)",
16-
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# Pre-configured namespace\u001b[39;00m\n\u001b[32m 2\u001b[39m workspace.list()\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m img = \u001b[43mworkspace\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mi001\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[32m 4\u001b[39m plotter.plot(img)\n\u001b[32m 5\u001b[39m workspace.save(\u001b[33m\"\u001b[39m\u001b[33manalysis.h5\u001b[39m\u001b[33m\"\u001b[39m)\n",
17-
"\u001b[36mFile \u001b[39m\u001b[32mC:\\Dev\\DataLab-Kernel\\datalab_kernel\\workspace.py:569\u001b[39m, in \u001b[36mWorkspace.get\u001b[39m\u001b[34m(self, name)\u001b[39m\n\u001b[32m 557\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mget\u001b[39m(\u001b[38;5;28mself\u001b[39m, name: \u001b[38;5;28mstr\u001b[39m) -> DataObject:\n\u001b[32m 558\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"Retrieve an object by name.\u001b[39;00m\n\u001b[32m 559\u001b[39m \n\u001b[32m 560\u001b[39m \u001b[33;03m Args:\u001b[39;00m\n\u001b[32m (...)\u001b[39m\u001b[32m 567\u001b[39m \u001b[33;03m KeyError: If object not found\u001b[39;00m\n\u001b[32m 568\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m569\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_backend\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[43mname\u001b[49m\u001b[43m)\u001b[49m\n",
18-
"\u001b[36mFile \u001b[39m\u001b[32mC:\\Dev\\DataLab-Kernel\\datalab_kernel\\workspace.py:104\u001b[39m, in \u001b[36mStandaloneBackend.get\u001b[39m\u001b[34m(self, name)\u001b[39m\n\u001b[32m 102\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m name \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m._objects:\n\u001b[32m 103\u001b[39m available = \u001b[33m\"\u001b[39m\u001b[33m, \u001b[39m\u001b[33m\"\u001b[39m.join(\u001b[38;5;28mself\u001b[39m._objects.keys()) \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m._objects \u001b[38;5;28;01melse\u001b[39;00m \u001b[33m\"\u001b[39m\u001b[33m(empty)\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m--> \u001b[39m\u001b[32m104\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(\n\u001b[32m 105\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mObject \u001b[39m\u001b[33m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33m not found. Available objects: [\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mavailable\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m]\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 106\u001b[39m )\n\u001b[32m 107\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._objects[name]\n",
19-
"\u001b[31mKeyError\u001b[39m: \"Object 'i001' not found. Available objects: [(empty)]\""
20-
]
21-
}
22-
],
8+
"outputs": [],
239
"source": [
2410
"# Pre-configured namespace\n",
2511
"workspace.list()\n",
@@ -28,10 +14,136 @@
2814
"workspace.save(\"analysis.h5\")"
2915
]
3016
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 4,
20+
"id": "70f86804-9dee-49eb-a941-16036fcd58b0",
21+
"metadata": {},
22+
"outputs": [],
23+
"source": [
24+
"import sigima.proc.image"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 6,
30+
"id": "7fd5f16d-c8a9-4860-ac26-2e7f400d3cee",
31+
"metadata": {},
32+
"outputs": [
33+
{
34+
"name": "stderr",
35+
"output_type": "stream",
36+
"text": [
37+
"C:\\Dev\\DataLab-Kernel\\.venv\\Lib\\site-packages\\scipy\\signal\\_signaltools.py:1783: RuntimeWarning: divide by zero encountered in divide\n",
38+
" res *= (1 - noise / lVar)\n"
39+
]
40+
}
41+
],
42+
"source": [
43+
"img2 = sigima.proc.image.wiener(img)"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": 9,
49+
"id": "eb8ac584-51cd-4d54-9323-43c7253acea4",
50+
"metadata": {},
51+
"outputs": [
52+
{
53+
"data": {
54+
"text/plain": [
55+
"<sigima.objects.image.object.ImageObj at 0x1a8238860f0>"
56+
]
57+
},
58+
"execution_count": 9,
59+
"metadata": {},
60+
"output_type": "execute_result"
61+
}
62+
],
63+
"source": [
64+
"workspace.add(\"G2\", img2)"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": 1,
70+
"id": "ee2db2d2-b90e-49ff-bdf5-2d3644a9c2ee",
71+
"metadata": {},
72+
"outputs": [
73+
{
74+
"data": {
75+
"text/plain": [
76+
"{'mode': 'live',\n",
77+
" 'backend': 'WebApiBackend',\n",
78+
" 'object_count': 0,\n",
79+
" 'url': 'http://127.0.0.1:8080'}"
80+
]
81+
},
82+
"execution_count": 1,
83+
"metadata": {},
84+
"output_type": "execute_result"
85+
}
86+
],
87+
"source": [
88+
"workspace.status()"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": 2,
94+
"id": "1cac845d-fc7a-43ee-aadd-d1dd09fee980",
95+
"metadata": {},
96+
"outputs": [
97+
{
98+
"name": "stdout",
99+
"output_type": "stream",
100+
"text": [
101+
"Help on method get in module datalab_kernel.workspace:\n",
102+
"\n",
103+
"get(name: 'str') -> 'DataObject' method of datalab_kernel.workspace.Workspace instance\n",
104+
" Retrieve an object by name.\n",
105+
"\n",
106+
" Args:\n",
107+
" name: Object name\n",
108+
"\n",
109+
" Returns:\n",
110+
" The requested object (SignalObj or ImageObj)\n",
111+
"\n",
112+
" Raises:\n",
113+
" KeyError: If object not found\n",
114+
"\n"
115+
]
116+
}
117+
],
118+
"source": [
119+
"help(workspace.get)"
120+
]
121+
},
122+
{
123+
"cell_type": "code",
124+
"execution_count": 9,
125+
"id": "70fb8bdb-04c7-4ab8-83ee-77ec007f030a",
126+
"metadata": {},
127+
"outputs": [
128+
{
129+
"data": {
130+
"text/plain": [
131+
"['Gauss(a=10,μ=0,σ=1),x0=0,y0=0)', 'Gauss']"
132+
]
133+
},
134+
"execution_count": 9,
135+
"metadata": {},
136+
"output_type": "execute_result"
137+
}
138+
],
139+
"source": [
140+
"workspace.list()"
141+
]
142+
},
31143
{
32144
"cell_type": "code",
33145
"execution_count": null,
34-
"id": "e755eccc-97e8-4e69-8d47-28bf06de9e86",
146+
"id": "dfc40d1e-2493-4cef-bb21-2326343620f6",
35147
"metadata": {},
36148
"outputs": [],
37149
"source": []

datalab_kernel/backends/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
Available backends:
1111
1212
- :class:`StandaloneBackend`: Local memory storage with HDF5 persistence
13-
- :class:`LiveBackend`: XML-RPC synchronization with DataLab (legacy)
14-
- :class:`WebApiBackend`: HTTP/JSON + NPZ synchronization with DataLab (recommended)
13+
- :class:`WebApiBackend`: HTTP/JSON + NPZ synchronization with DataLab
1514
"""
1615

1716
from __future__ import annotations
@@ -22,10 +21,11 @@
2221
"WorkspaceBackend",
2322
]
2423

25-
# Re-export base classes from workspace module for convenience
26-
from datalab_kernel.workspace import StandaloneBackend, WorkspaceBackend
24+
# Re-export base class from workspace module for convenience
25+
# Import backends
26+
from datalab_kernel.backends.standalone import StandaloneBackend
27+
from datalab_kernel.workspace import WorkspaceBackend
2728

28-
# Import WebAPI backend (handles missing dependencies gracefully)
2929
try:
3030
from datalab_kernel.backends.webapi import WebApiBackend
3131
except ImportError:

0 commit comments

Comments
 (0)