Skip to content

Commit 609e248

Browse files
Copilotkjy5
andauthored
Remove proxy feature (#501)
* Initial plan * Remove proxy feature from CLI, GUI, server, and tests Co-authored-by: kjy5 <[email protected]> * Fix linting issues and remove unused code Co-authored-by: kjy5 <[email protected]> * Fix doc generation warnings * Update dependencies --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: kjy5 <[email protected]> Co-authored-by: Kenneth Yang <[email protected]>
1 parent d567770 commit 609e248

File tree

9 files changed

+19
-253
lines changed

9 files changed

+19
-253
lines changed

docs/development/socketio_api.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@ Response:
3737
- `"2.0.0"`
3838
- `"2.0.0b2`
3939

40-
### Get Pinpoint ID
41-
42-
| Event | Input | Response |
43-
|-------------------|-------|----------|
44-
| `get_pinpoint_id` | None | `string` |
45-
46-
Proxy connection ID (first 8 characters of a UUID v4).
47-
48-
__Example:__
49-
50-
Input: None
51-
52-
Response: `"81f8de08"`
53-
5440
### Get Platform Info
5541

5642
| Event | Input | Return |

docs/usage/experiment_automation.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,6 @@ nav:
107107
- development/index.md
108108
- development/socketio_api.md
109109
- development/adding_a_manipulator.md
110+
- development/jackhammer_mode.md
110111
- development/code_organization.md
111112
- Source Code Reference: reference/

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ dependencies = [
3131
"packaging==25.0",
3232
"platformdirs==4.5.1",
3333
"pyserial==3.5",
34-
"python-socketio[asyncio_client]==5.15.1",
34+
"python-socketio==5.15.1",
3535
"requests==2.32.5",
3636
"sensapex==1.504.1",
3737
"rich==14.2.0",
38-
"vbl-aquarium==1.1.0"
38+
"vbl-aquarium==1.2.0"
3939
]
4040

4141
[project.urls]

src/ephys_link/back_end/server.py

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@
1212
```
1313
"""
1414

15-
from asyncio import new_event_loop, run
15+
from asyncio import new_event_loop
1616
from collections.abc import Callable, Coroutine
1717
from json import JSONDecodeError, dumps, loads
1818
from typing import Any, TypeVar, final
19-
from uuid import uuid4
2019

2120
from aiohttp.web import Application, run_app
2221
from pydantic import ValidationError
23-
from socketio import AsyncClient, AsyncServer # pyright: ignore [reportMissingTypeStubs]
22+
from socketio import AsyncServer # pyright: ignore [reportMissingTypeStubs]
2423
from vbl_aquarium.models.ephys_link import (
2524
EphysLinkOptions,
2625
SetDepthRequest,
2726
SetInsideBrainRequest,
2827
SetPositionRequest,
2928
)
30-
from vbl_aquarium.models.proxy import PinpointIdResponse
3129
from vbl_aquarium.utils.vbl_base_model import VBLBaseModel
3230

3331
from ephys_link.__about__ import __version__
@@ -36,8 +34,6 @@
3634
from ephys_link.utils.constants import (
3735
MALFORMED_REQUEST_ERROR,
3836
PORT,
39-
PROXY_CLIENT_NOT_INITIALIZED_ERROR,
40-
SERVER_NOT_INITIALIZED_ERROR,
4137
UNKNOWN_EVENT_ERROR,
4238
cannot_connect_as_client_is_already_connected_error,
4339
client_disconnected_without_being_connected_error,
@@ -64,35 +60,24 @@ def __init__(self, options: EphysLinkOptions, platform_handler: PlatformHandler,
6460
self._platform_handler = platform_handler
6561
self._console = console
6662

67-
# Initialize based on proxy usage.
68-
self._sio: AsyncServer | AsyncClient = AsyncClient() if self._options.use_proxy else AsyncServer()
69-
if not self._options.use_proxy:
70-
# Exit if _sio is not a Server.
71-
if not isinstance(self._sio, AsyncServer):
72-
self._console.critical_print(SERVER_NOT_INITIALIZED_ERROR)
73-
raise TypeError(SERVER_NOT_INITIALIZED_ERROR)
63+
# Initialize server.
64+
self._sio: AsyncServer = AsyncServer()
7465

75-
self._app = Application()
76-
self._sio.attach(self._app) # pyright: ignore [reportUnknownMemberType]
66+
self._app = Application()
67+
self._sio.attach(self._app) # pyright: ignore [reportUnknownMemberType]
7768

78-
# Bind connection events.
79-
_ = self._sio.on("connect", self.connect) # pyright: ignore [reportUnknownMemberType, reportUnknownVariableType]
80-
_ = self._sio.on("disconnect", self.disconnect) # pyright: ignore [reportUnknownMemberType, reportUnknownVariableType]
69+
# Bind connection events.
70+
_ = self._sio.on("connect", self.connect) # pyright: ignore [reportUnknownMemberType, reportUnknownVariableType]
71+
_ = self._sio.on("disconnect", self.disconnect) # pyright: ignore [reportUnknownMemberType, reportUnknownVariableType]
8172

8273
# Store connected client.
8374
self._client_sid: str = ""
8475

85-
# Generate Pinpoint ID for proxy usage.
86-
self._pinpoint_id = str(uuid4())[:8]
87-
8876
# Bind events.
8977
_ = self._sio.on("*", self.platform_event_handler) # pyright: ignore [reportUnknownMemberType, reportUnknownVariableType]
9078

9179
def launch(self) -> None:
92-
"""Launch the server.
93-
94-
Based on the options, either connect to a proxy or launch the server locally.
95-
"""
80+
"""Launch the server."""
9681

9782
# List platform and available manipulators.
9883
self._console.info_print("PLATFORM", self._platform_handler.get_display_name())
@@ -108,22 +93,7 @@ def launch(self) -> None:
10893
loop.close()
10994

11095
# Launch server
111-
if self._options.use_proxy:
112-
self._console.info_print("PINPOINT ID", self._pinpoint_id)
113-
114-
async def connect_proxy() -> None:
115-
# Exit if _sio is not a proxy client.
116-
if not isinstance(self._sio, AsyncClient):
117-
self._console.critical_print(PROXY_CLIENT_NOT_INITIALIZED_ERROR)
118-
raise TypeError(PROXY_CLIENT_NOT_INITIALIZED_ERROR)
119-
120-
# noinspection HttpUrlsUsage
121-
await self._sio.connect(f"http://{self._options.proxy_address}:{PORT}") # pyright: ignore [reportUnknownMemberType]
122-
await self._sio.wait()
123-
124-
run(connect_proxy())
125-
else:
126-
run_app(self._app, port=PORT)
96+
run_app(self._app, port=PORT)
12797

12898
# Helper functions.
12999
def _malformed_request_response(self, request: str, data: tuple[tuple[Any], ...]) -> str: # pyright: ignore [reportExplicitAny]
@@ -250,8 +220,6 @@ async def platform_event_handler(self, event: str, _: str, data: Any) -> str: #
250220
# Server metadata.
251221
case "get_version":
252222
return __version__
253-
case "get_pinpoint_id":
254-
return PinpointIdResponse(pinpoint_id=self._pinpoint_id, is_requester=False).to_json_string()
255223
case "get_platform_info":
256224
return (await self._platform_handler.get_platform_info()).to_json_string()
257225

src/ephys_link/front_end/cli.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,6 @@ def __init__(self) -> None:
5656
action="store_true",
5757
help="Enable debug mode.",
5858
)
59-
_ = self._parser.add_argument(
60-
"-p",
61-
"--use-proxy",
62-
dest="use_proxy",
63-
action="store_true",
64-
help="Enable proxy mode.",
65-
)
66-
_ = self._parser.add_argument(
67-
"-a",
68-
"--proxy-address",
69-
type=str,
70-
default="proxy2.virtualbrainlab.org",
71-
dest="proxy_address",
72-
help="Proxy IP address.",
73-
)
7459
_ = self._parser.add_argument(
7560
"--mpm-port",
7661
type=int,

src/ephys_link/front_end/gui.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ def __init__(self) -> None:
5252
self._ignore_updates = BooleanVar(value=options.ignore_updates)
5353
self._type = StringVar(value=options.type)
5454
self._debug = BooleanVar(value=options.debug)
55-
self._use_proxy = BooleanVar(value=options.use_proxy)
56-
self._proxy_address = StringVar(value=options.proxy_address)
5755
self._mpm_port = IntVar(value=options.mpm_port)
5856
self._serial = StringVar(value=options.serial)
5957

@@ -80,8 +78,6 @@ def get_options(self) -> EphysLinkOptions:
8078
ignore_updates=self._ignore_updates.get(),
8179
type=self._type.get(),
8280
debug=self._debug.get(),
83-
use_proxy=self._use_proxy.get(),
84-
proxy_address=self._proxy_address.get(),
8581
mpm_port=self._mpm_port.get(),
8682
serial=self._serial.get(),
8783
)
@@ -115,40 +111,23 @@ def _build_gui(self) -> None:
115111
ttk.Label(server_serving_settings, text="Local IP:", anchor=E, justify=RIGHT).grid(column=0, row=0, sticky="we")
116112
ttk.Label(server_serving_settings, text=gethostbyname(gethostname())).grid(column=1, row=0, sticky="we")
117113

118-
# Proxy.
119-
ttk.Label(server_serving_settings, text="Use Proxy:", anchor=E, justify=RIGHT).grid(
120-
column=0, row=1, sticky="we"
121-
)
122-
ttk.Checkbutton(
123-
server_serving_settings,
124-
variable=self._use_proxy,
125-
).grid(column=1, row=1, sticky="we")
126-
127-
# Proxy address.
128-
ttk.Label(server_serving_settings, text="Proxy Address:", anchor=E, justify=RIGHT).grid(
129-
column=0, row=2, sticky="we"
130-
)
131-
ttk.Entry(server_serving_settings, textvariable=self._proxy_address, justify=CENTER).grid(
132-
column=1, row=2, sticky="we"
133-
)
134-
135114
# Ignore updates.
136115
ttk.Label(server_serving_settings, text="Ignore Updates:", anchor=E, justify=RIGHT).grid(
137-
column=0, row=4, sticky="we"
116+
column=0, row=1, sticky="we"
138117
)
139118
ttk.Checkbutton(
140119
server_serving_settings,
141120
variable=self._ignore_updates,
142-
).grid(column=1, row=4, sticky="we")
121+
).grid(column=1, row=1, sticky="we")
143122

144123
# Debug mode.
145124
ttk.Label(server_serving_settings, text="Debug mode:", anchor=E, justify=RIGHT).grid(
146-
column=0, row=5, sticky="we"
125+
column=0, row=2, sticky="we"
147126
)
148127
ttk.Checkbutton(
149128
server_serving_settings,
150129
variable=self._debug,
151-
).grid(column=1, row=5, sticky="we")
130+
).grid(column=1, row=2, sticky="we")
152131

153132
# ---
154133

src/ephys_link/utils/constants.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ def did_not_reach_target_depth_error(request: SetDepthRequest, final_unified_dep
5858

5959
EMERGENCY_STOP_MESSAGE = "Emergency Stopping All Manipulators..."
6060

61-
SERVER_NOT_INITIALIZED_ERROR = "Server not initialized."
62-
PROXY_CLIENT_NOT_INITIALIZED_ERROR = "Proxy client not initialized."
63-
6461

6562
def cannot_connect_as_client_is_already_connected_error(new_client_sid: str, current_client_sid: str) -> str:
6663
"""Generate an error message for when the client is already connected.

0 commit comments

Comments
 (0)