Skip to content

Commit

Permalink
329 support launching from pinpoint (#330)
Browse files Browse the repository at this point in the history
* Launch GUI on argc == 0 and added ignore update flag

* Version bump, ignore updates flag

* Version bump

* Add requests as a requirement

* Updated README

* Add clean build option

* Bump version, re-add background option (no-op)

* Fix lint error
  • Loading branch information
kjy5 authored Mar 4, 2024
1 parent b95501e commit c4c2752
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 27 deletions.
6 changes: 0 additions & 6 deletions .idea/ruff.xml

This file was deleted.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ the [API reference](https://virtualbrainlab.org/api_reference_ephys_link.html).
is currently designed to interface with local/desktop instances of Pinpoint. It
will not work with the web browser versions of Pinpoint at this time.

## Launch from Pinpoint (Recommended)

Pinpoint comes bundled with the correct version of Ephys Link. If you are using Pinpoint on the same computer your
manipulators are connected to, you can launch the server from within Pinpoint. Follow the instructions in
the [Pinpoint documentation](https://virtualbrainlab.org/pinpoint/tutorials/tutorial_ephys_link.html#configure-and-launch-ephys-link).

## Install as Standalone Executable

1. Download the latest executable from
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies = [
"pyserial==3.5",
"python-socketio==5.11.1",
"pythonnet==3.0.3",
"requests==2.31.0",
"wheel==0.42.0",
"sensapex==1.400.0",
]
Expand Down Expand Up @@ -91,6 +92,7 @@ dependencies = [
]
[tool.hatch.envs.exe.scripts]
build = "pyinstaller.exe ephys_link.spec -y"
build_clean = "pyinstaller.exe ephys_link.spec -y --clean"

[tool.coverage.run]
source_pkgs = ["ephys_link", "tests"]
Expand Down
2 changes: 1 addition & 1 deletion src/ephys_link/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.6.dev0"
__version__ = "1.2.7"
24 changes: 13 additions & 11 deletions src/ephys_link/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from argparse import ArgumentParser
from sys import argv

from ephys_link import common as com
from ephys_link.__about__ import __version__ as version
Expand All @@ -9,35 +10,36 @@
# Setup argument parser.
parser = ArgumentParser(
description="Electrophysiology Manipulator Link: a websocket interface for"
" manipulators in electrophysiology experiments",
" manipulators in electrophysiology experiments.",
prog="python -m ephys-link",
)
parser.add_argument("-b", "--background", dest="background", action="store_true", help="Skip configuration window.")
parser.add_argument(
"-b", "--background", dest="background", action="store_true", help="Launches in headless mode (no GUI)"
"-i", "--ignore-updates", dest="ignore_updates", action="store_true", help="Skip (ignore) checking for updates."
)
parser.add_argument(
"-t",
"--type",
type=str,
dest="type",
default="sensapex",
help='Manipulator type (i.e. "sensapex", "new_scale", or "new_scale_pathfinder").' ' Default: "sensapex"',
help='Manipulator type (i.e. "sensapex", "new_scale", or "new_scale_pathfinder"). Default: "sensapex".',
)
parser.add_argument("-d", "--debug", dest="debug", action="store_true", help="Enable debug mode")
parser.add_argument("-d", "--debug", dest="debug", action="store_true", help="Enable debug mode.")
parser.add_argument(
"-p",
"--port",
type=int,
default=8081,
dest="port",
help="Port to serve on. Default: 8081 (avoids conflict with other HTTP servers)",
help="Port to serve on. Default: 8081 (avoids conflict with other HTTP servers).",
)
parser.add_argument(
"--pathfinder_port",
type=int,
default=8080,
dest="pathfinder_port",
help="Port New Scale Pathfinder's server is on. Default: 8080",
help="Port New Scale Pathfinder's server is on. Default: 8080.",
)
parser.add_argument(
"-s",
Expand All @@ -46,14 +48,14 @@
default="no-e-stop",
dest="serial",
nargs="?",
help="Emergency stop serial port (i.e. COM3). Default: disables emergency stop",
help="Emergency stop serial port (i.e. COM3). Default: disables emergency stop.",
)
parser.add_argument(
"-v",
"--version",
action="version",
version=f"Electrophysiology Manipulator Link v{version}",
help="Print version and exit",
help="Print version and exit.",
)


Expand All @@ -63,8 +65,8 @@ def main() -> None:
# Parse arguments.
args = parser.parse_args()

# Launch GUI if not background.
if not args.background:
# Launch GUI if there are no CLI arguments.
if len(argv) == 1:
gui = GUI()
gui.launch()
return None
Expand All @@ -81,7 +83,7 @@ def main() -> None:
e_stop.watch()

# Launch with parsed arguments on main thread.
server.launch(args.type, args.port, args.pathfinder_port)
server.launch(args.type, args.port, args.pathfinder_port, args.ignore_updates)


if __name__ == "__main__":
Expand Down
27 changes: 18 additions & 9 deletions src/ephys_link/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,13 @@ async def catch_all(_, __, data: Any) -> str:
print(f"[UNKNOWN EVENT]:\t {data}")
return "UNKNOWN_EVENT"

def launch(self, platform_type: str, server_port: int, pathfinder_port: int | None = None) -> None:
def launch(
self,
platform_type: str,
server_port: int,
pathfinder_port: int | None = None,
ignore_updates: bool = False, # noqa: FBT002
) -> None:
"""Launch the server.
:param platform_type: Parsed argument for platform type.
Expand All @@ -378,6 +384,8 @@ def launch(self, platform_type: str, server_port: int, pathfinder_port: int | No
:type server_port: int
:param pathfinder_port: Port New Scale Pathfinder's server is on.
:type pathfinder_port: int
:param ignore_updates: Flag to ignore checking for updates.
:type ignore_updates: bool
:return: None
"""

Expand All @@ -399,14 +407,15 @@ def launch(self, platform_type: str, server_port: int, pathfinder_port: int | No
print(f"v{__version__}")

# Check for newer version.
try:
version_request = get("https://api.github.com/repos/VirtualBrainLab/ephys-link/tags", timeout=10)
latest_version = version_request.json()[0]["name"]
if version.parse(latest_version) > version.parse(__version__):
print(f"New version available: {latest_version}")
print("Download at: https://github.com/VirtualBrainLab/ephys-link/releases/latest")
except ConnectionError:
pass
if not ignore_updates:
try:
version_request = get("https://api.github.com/repos/VirtualBrainLab/ephys-link/tags", timeout=10)
latest_version = version_request.json()[0]["name"]
if version.parse(latest_version) > version.parse(__version__):
print(f"New version available: {latest_version}")
print("Download at: https://github.com/VirtualBrainLab/ephys-link/releases/latest")
except ConnectionError:
pass

# Explain window.
print()
Expand Down

0 comments on commit c4c2752

Please sign in to comment.