Skip to content

Commit

Permalink
237 do all imports at the start (#284)
Browse files Browse the repository at this point in the history
* Removed matrix versions

* Removed usages of importlib

* Load DLL in __init__

* Version bumpb

* Updated README and security notice

* Updated OSS note
  • Loading branch information
kjy5 authored Jan 19, 2024
1 parent 0ecb725 commit 6e210c7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ This project is in its early stages, and we are open to suggestions and contribu

| Version | Supported |
|---------|--------------------|
| 0.0.1 | :white_check_mark: |
| 1.1.x | :white_check_mark: |
| 1.0.x | :x: |

## Reporting a Vulnerability

Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ Socket.IO-compliant application (such
as [Pinpoint](https://github.com/VirtualBrainLab/Pinpoint))
to communicate with manipulators used in electrophysiology experiments.

Currently, Ephys Link only supports Sensapex uMp-4 and uMp-3 Micromanipulators and New Scale 3-axis
manipulators. However, this platform is designed to be extensible to other
manipulators and more may be added in the future.
**Supported Manipulators:**

| Manufacturer | Model |
|--------------|-------------------------------------------------------------------|
| Sensapex | <ul> <li>uMp-4</li> <li>uMp-3</li> </ul> |
| New Scale | <ul> <li>Pathfinder MPM Control</li> <li>M3-USB-3:1-EP</li> </ul> |

Ephys Link is an open and extensible platform. It is designed to easily support integration with other manipulators.

For more information regarding the server's implementation and how the code is organized, see
the [package's development documentation](https://virtualbrainlab.org/ephys_link/development.html).
Expand All @@ -31,7 +36,8 @@ the [API reference](https://virtualbrainlab.org/api_reference_ephys_link.html).
1. [Python ≥ 3.8, < 3.13](https://www.python.org/downloads/release/python-3116/)
1. Python 3.12+ requires the latest version
of Microsoft Visual C++ (MSVC v143+ x86/64) and the Windows SDK (10/11) to
be installed. They can be acquired through the [Visual Studio Build Tools Installer](https://visualstudio.microsoft.com/visual-cpp-build-tools/).
be installed. They can be acquired through
the [Visual Studio Build Tools Installer](https://visualstudio.microsoft.com/visual-cpp-build-tools/).
2. An **x86 Windows PC is required** to run the server.
3. For Sensapex devices, the controller unit must be connected via an ethernet
cable and powered. A USB-to-ethernet adapter is acceptable. For New Scale manipulators,
Expand Down Expand Up @@ -76,7 +82,7 @@ pip install --upgrade ephys-link
```bash
hatch shell
```

This will create a virtual environment and install the package in editable mode.

# Usage
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ cov = [
"cov-report",
]

[[tool.hatch.envs.all.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]
#[[tool.hatch.envs.all.matrix]]
#python = ["3.8", "3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.types]
dependencies = [
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.1.0"
__version__ = "1.1.1"
5 changes: 5 additions & 0 deletions src/ephys_link/platforms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import clr

# Load New Scale API
# noinspection PyUnresolvedReferences
clr.AddReference("ephys_link/resources/NstMotorCtrl")
16 changes: 4 additions & 12 deletions src/ephys_link/platforms/new_scale_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

from __future__ import annotations

import importlib
from typing import TYPE_CHECKING

# noinspection PyPackageRequirements
import clr
# noinspection PyUnresolvedReferences
from NstMotorCtrl import NstCtrlHostIntf

from ephys_link import common as com
from ephys_link.platform_handler import PlatformHandler
from ephys_link.platforms.new_scale_manipulator import NewScaleManipulator

if TYPE_CHECKING:
import socketio
Expand All @@ -30,12 +30,6 @@ def __init__(self) -> None:
self.num_axes = 3
self.dimensions = [15, 15, 15]

# Load New Scale API
# noinspection PyUnresolvedReferences
clr.AddReference("ephys_link/resources/NstMotorCtrl")
# noinspection PyUnresolvedReferences
from NstMotorCtrl import NstCtrlHostIntf

self.ctrl = NstCtrlHostIntf()

# Connect manipulators and initialize
Expand Down Expand Up @@ -63,9 +57,7 @@ def _register_manipulator(self, manipulator_id: str) -> None:

# Register manipulator
first_axis_index = int(manipulator_id) * 3
self.manipulators[manipulator_id] = importlib.import_module(
"ephys_link.platforms.new_scale_manipulator"
).NewScaleManipulator(
self.manipulators[manipulator_id] = NewScaleManipulator(
manipulator_id,
self.ctrl.GetAxis(first_axis_index),
self.ctrl.GetAxis(first_axis_index + 1),
Expand Down
23 changes: 9 additions & 14 deletions src/ephys_link/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@
4. Relay the response from :mod:`ephys_link.sensapex_handler` to the callback function
"""

import importlib
import json
import sys
from typing import TYPE_CHECKING, Any

import socketio
from aiohttp import web
from aiohttp.web_runner import GracefulExit
from pythonnet import load

from ephys_link import common as com
from ephys_link.__about__ import __version__ as version
from ephys_link.platforms.new_scale_handler import NewScaleHandler
from ephys_link.platforms.new_scale_pathfinder_handler import NewScalePathfinderHandler
from ephys_link.platforms.sensapex_handler import SensapexHandler
from ephys_link.platforms.ump3_handler import UMP3Handler

if TYPE_CHECKING:
from ephys_link.platform_handler import PlatformHandler

# Setup server
load("netfx")


class Server:
def __init__(self):
Expand All @@ -42,9 +41,7 @@ def __init__(self):
self.is_running = False

# Current platform handler (defaults to Sensapex)
self.platform: PlatformHandler = importlib.import_module(
"ephys_link.platforms.sensapex_handler"
).SensapexHandler()
self.platform: PlatformHandler = SensapexHandler()

# Attach server to the web app
self.sio.attach(self.app)
Expand Down Expand Up @@ -366,16 +363,14 @@ def launch_server(self, platform_type: str, server_port: int, pathfinder_port: i

# Import correct manipulator handler
if platform_type == "sensapex":
# Already imported (was the default)
# Already assigned (was the default)
pass
elif platform_type == "ump3":
self.platform = importlib.import_module("ephys_link.platforms.ump3_handler").UMP3Handler()
self.platform = UMP3Handler()
elif platform_type == "new_scale":
self.platform = importlib.import_module("ephys_link.platforms.new_scale_handler").NewScaleHandler()
self.platform = NewScaleHandler()
elif platform_type == "new_scale_pathfinder":
self.platform = importlib.import_module(
"ephys_link.platforms.new_scale_pathfinder_handler"
).NewScalePathfinderHandler(pathfinder_port)
self.platform = NewScalePathfinderHandler(pathfinder_port)
else:
sys.exit(f"[ERROR]\t\t Invalid manipulator type: {platform_type}")

Expand Down

0 comments on commit 6e210c7

Please sign in to comment.