From c4c2752d2f79c764101838a9d167aa9176965ad8 Mon Sep 17 00:00:00 2001 From: Kenneth Yang <82800265+kjy5@users.noreply.github.com> Date: Mon, 4 Mar 2024 13:21:55 -0800 Subject: [PATCH] 329 support launching from pinpoint (#330) * 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 --- .idea/ruff.xml | 6 ------ README.md | 6 ++++++ pyproject.toml | 2 ++ src/ephys_link/__about__.py | 2 +- src/ephys_link/__main__.py | 24 +++++++++++++----------- src/ephys_link/server.py | 27 ++++++++++++++++++--------- 6 files changed, 40 insertions(+), 27 deletions(-) delete mode 100644 .idea/ruff.xml diff --git a/.idea/ruff.xml b/.idea/ruff.xml deleted file mode 100644 index b87cfd6..0000000 --- a/.idea/ruff.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/README.md b/README.md index cea6c59..7a06d88 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 550d4a3..6526a1b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", ] @@ -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"] diff --git a/src/ephys_link/__about__.py b/src/ephys_link/__about__.py index 9924c20..7f647d0 100644 --- a/src/ephys_link/__about__.py +++ b/src/ephys_link/__about__.py @@ -1 +1 @@ -__version__ = "1.2.6.dev0" +__version__ = "1.2.7" diff --git a/src/ephys_link/__main__.py b/src/ephys_link/__main__.py index b9e5652..1b0c64a 100644 --- a/src/ephys_link/__main__.py +++ b/src/ephys_link/__main__.py @@ -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 @@ -9,11 +10,12 @@ # 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", @@ -21,23 +23,23 @@ 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", @@ -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.", ) @@ -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 @@ -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__": diff --git a/src/ephys_link/server.py b/src/ephys_link/server.py index 021e4a5..ba45ad5 100644 --- a/src/ephys_link/server.py +++ b/src/ephys_link/server.py @@ -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. @@ -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 """ @@ -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://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://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()